javascript - Can't enable/disable textbox when toggling checkbox -


this code.jsp file , i've written javascript in enable/disable textbox name=uinp when toggling checkbox name=input not working!

<html> <body>     <form action="compile.jsp" method="get">          custom input: <input type="checkbox" name="input" onchange="toggle('input','uinp')"><br><br>              <textarea rows="5" cols="15" name="uinp" style="display: none"></textarea><br><br>         <br><input type="submit" value="submit">         <input type="reset" value="cancel">     </form>     <script>        function toggle(chk,txt)        {                  if(document.getelementbyid(chk).checked)                   document.getelementbyid(txt).style.display='';             else                document.getelementbyid(txt).style.display='none';        }     </script> </body> </html> 

please me this!

you need set id textarea otherwise getelementbyid() returns null, since there no element id. can pass this context refer checkbox.

<form action="compile.jsp" method="get">    custom input:    <input type="checkbox" name="input" onchange="toggle(this,'uinp')">    <br>    <br>    <textarea rows="5" cols="15" id="uinp" style="display: none"></textarea>    <br>    <br>    <br>    <input type="submit" value="submit">    <input type="reset" value="cancel">  </form>  <script>    function toggle(ele, txt) {      if (ele.checked)        document.getelementbyid(txt).style.display = '';      else        document.getelementbyid(txt).style.display = 'none';    }  </script>


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -