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
Post a Comment