1 Reply Latest reply on Jul 10, 2012 12:10 AM by BHAKTA RANJAN SATAPATHY

    Issues with javascript enable/disable

      Hey,I have been trying to click on one button which inturns enable another button.I tried using that in html and running on the browser but if I try the same thing in RhoSimulator,it doesnt work.

      Consider this example for instance...

      Try running this on browser and then on RhoSimulator,you will find the difference.

      <html>

      <head>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <script type="text/javascript">

         function disable(buttonid){

          var button1_name;

          var button2_name;

          if(buttonid=="button1"){

           button1_name=document.getElementById('button1').name;

           button1_name++;

           document.getElementById('button1').name=button1_name;

           alert("Click Button 1 :: "+document.getElementById('button1').name)

          }else{

           button2_name=document.getElementById('button2').name;

           button2_name++;

           document.getElementById('button2').name=button2_name;

           alert("Click Button 2 :: "+document.getElementById('button2').name)

          }

         if(button1_name==3){

           document.getElementById('button1').disabled = true;

           document.getElementById('button2').disabled = false;

           document.getElementById('button1').name=0;

          }

         if(button2_name==3){

           document.getElementById('button2').disabled = true;

           document.getElementById('button1').disabled = false;

           document.getElementById('button2').name=0;

          }

        }

      </script>

      </meta>

      </head>

      <body>

      <table align="center" >

        <tr>

         <td><input type="button" id="button1" name="0"

             value="Button 1" onclick="disable(this.id)" /></td>

        </tr>

        <tr>

         <td><input type="button"  id="button2"  name="0" disabled

           value="Button 2" onclick="disable(this.id)" /></td>

        </tr>

      </table>

      </body>

      </html>

       

      Urgent help required.Thanks a lot.

        • Re: Issues with javascript enable/disable
          BHAKTA RANJAN SATAPATHY

          Hi Madan,

           

          I have checked your code and ran inside RhoSimulator. Every thing works fine for me.

          The code you have given i created a file(say test.html) and put into /app/test.html

          Then from index.erb i have given a link to open test.html. And after three time clicks on button A , Button B is getting enabled and Button A is getting Disabled .

           

          I believe your javascript is not loaded properly , after launching application in RhoSimulator try to refresh the page and check. or put the javascript code after <body> tag.

           

          Hope this will help you, and there is no problem with your code too.

           

          Thanks