Why doesn't my javascript code work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • UKJohnny
    New Member
    • Jul 2013
    • 2

    Why doesn't my javascript code work

    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?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    How can I make both scripts work on the one page?
    don’t use the same name for different functions.

    Comment

    • UKJohnny
      New Member
      • Jul 2013
      • 2

      #3
      "don’t use the same name for different functions". I don't think I have used the same name. Aren't "function validate(myButt on1)" and "function validate(myButt on2)" separate names or am I confused? How do you suggest I change it?
      Last edited by UKJohnny; Jul 16 '13, 10:19 PM. Reason: Typo

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        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.

        Comment

        • Exequiel
          Contributor
          • Jul 2012
          • 288

          #5
          you must have two functions, validate(myButt on1) and validates(myBut ton2), you can also create the situition in one funtion but you need a condition to it.

          Comment

          • ajunboys
            New Member
            • Jul 2013
            • 2

            #6
            hi,baby.u functions define error.two functions[validate(myButt on1) and validates(myBut ton2)] name and arguments totality is equal.the function validates(myBut ton2) will replace to the validate(myButt on1).
            so, button1 and button2 invoking validate(myButt on2).
            Code:
            <script language="javascript" type="text/javascript">
                   	function validate(myButton1){
            		var  myButton1= document.getElementById('myButton1');
            		var  myDIV1= document.getElementById('DIV1');
            		setTimeout (function(DIV1){myButton1.style.display ='none';  },1);
            		setTimeout (function(DIV1){myDIV1.style.display ='inline'; },1);
            		}
            </script>
            <script language="javascript" type="text/javascript">
                   	function validate(myButton2){
            		var  myButton2= document.getElementById('myButton2');
            		var  myDIV2= document.getElementById('DIV2');
            		setTimeout (function(DIV2){myButton2.style.display ='none';  },1);
            		setTimeout (function(DIV2){myDIV2.style.display ='inline'; },1);
            		}
            </script>

            Comment

            • Exequiel
              Contributor
              • Jul 2012
              • 288

              #7
              my suggestion is right and its working, he can create that two function,
              Code:
              <script language="javascript" type="text/javascript">
                         function validate(myButton1){
                      var  myButton1= document.getElementById('myButton1');
                      var  myDIV1= document.getElementById('DIV1');
                      setTimeout (function(DIV1){myButton1.style.display ='none';  },1);
                      setTimeout (function(DIV1){myDIV1.style.display ='inline'; },1);
                      }
              </script>
              <script language="javascript" type="text/javascript">
                         function validates(myButton2){
                      var  myButton2= document.getElementById('myButton2');
                      var  myDIV2= document.getElementById('DIV2');
                      setTimeout (function(DIV2){myButton2.style.display ='none';  },1);
                      setTimeout (function(DIV2){myDIV2.style.display ='inline'; },1);
                      }
              </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,

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5388

                #8
                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.

                Comment

                Working...