By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

Why doesn't my javascript code work

P: 2
Can anyone help me with a JavaScript problem?
If you go to www.bidets4sale.com/test.htm you will see my webpage and if you right click on it you should be able to view the code.
I have two scripts but if you click on the top button (the button 1 script) it executes the button2 script.
How can I make both scripts work on the one page?
Jul 16 '13 #1

✓ answered by Exequiel

you must have two functions, validate(myButton1) and validates(myButton2), you can also create the situition in one funtion but you need a condition to it.

Share this Question
Share on Google+
7 Replies


Dormilich
Expert Mod 5K+
P: 8,639
How can I make both scripts work on the one page?
donít use the same name for different functions.
Jul 16 '13 #2

P: 2
"don’t use the same name for different functions". I don't think I have used the same name. Aren't "function validate(myButton1)" and "function validate(myButton2)" separate names or am I confused? How do you suggest I change it?
Jul 16 '13 #3

Rabbit
Expert Mod 10K+
P: 12,359
That's two functions with the same function name. They just have different names for the input varibles. Input variables are not part of the function name.
Jul 16 '13 #4

Exequiel
100+
P: 287
you must have two functions, validate(myButton1) and validates(myButton2), you can also create the situition in one funtion but you need a condition to it.
Jul 17 '13 #5

P: 2
hi,baby.u functions define error.two functions[validate(myButton1) and validates(myButton2)] name and arguments totality is equal.the function validates(myButton2) will replace to the validate(myButton1).
so, button1 and button2 invoking validate(myButton2).
Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="javascript" type="text/javascript">
  3.            function validate(myButton1){
  4.         var  myButton1= document.getElementById('myButton1');
  5.         var  myDIV1= document.getElementById('DIV1');
  6.         setTimeout (function(DIV1){myButton1.style.display ='none';  },1);
  7.         setTimeout (function(DIV1){myDIV1.style.display ='inline'; },1);
  8.         }
  9. </script>
  10. <script language="javascript" type="text/javascript">
  11.            function validate(myButton2){
  12.         var  myButton2= document.getElementById('myButton2');
  13.         var  myDIV2= document.getElementById('DIV2');
  14.         setTimeout (function(DIV2){myButton2.style.display ='none';  },1);
  15.         setTimeout (function(DIV2){myDIV2.style.display ='inline'; },1);
  16.         }
  17. </script>
  18.  
Jul 17 '13 #6

Exequiel
100+
P: 287
my suggestion is right and its working, he can create that two function,
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2.            function validate(myButton1){
  3.         var  myButton1= document.getElementById('myButton1');
  4.         var  myDIV1= document.getElementById('DIV1');
  5.         setTimeout (function(DIV1){myButton1.style.display ='none';  },1);
  6.         setTimeout (function(DIV1){myDIV1.style.display ='inline'; },1);
  7.         }
  8. </script>
  9. <script language="javascript" type="text/javascript">
  10.            function validates(myButton2){
  11.         var  myButton2= document.getElementById('myButton2');
  12.         var  myDIV2= document.getElementById('DIV2');
  13.         setTimeout (function(DIV2){myButton2.style.display ='none';  },1);
  14.         setTimeout (function(DIV2){myDIV2.style.display ='inline'; },1);
  15.         }
  16. </script>
,
he can also create his situition in only one function by determining if the button that been click is button1 or button2. . . , I suggest he can use Jquery for easy coding,
Jul 17 '13 #7

gits
Expert Mod 5K+
P: 5,298
if nothing else of jQuery is used in the page - then i strongly recommend to NOT use it for such simple things. its a complete useless overhead to have a complete lib included without the need for it. and its not 'easier' with jQuery - at best a bit more convenient. there is not need to fire a rocket on a mosquito.
Jul 17 '13 #8

Post your reply

Sign in to post your reply or Sign up for a free account.