Jump to content

Javascript to enable/disable form elements?


alkindyss

Recommended Posts

check this code, i dont know whats wrong. it should disable the text box when i click on the checkbox but it doesnt, please help.

<html><body><input type="checkbox" id="check1"><input type="text" id="bla"><script type="text/javascript">if (document.getElementById('check1').value == true){    document.getElementById('bla').disabled = true}	</script></body></html>

Link to comment
Share on other sites

try this

<html><head><script type="text/javascript">	function setState(elemId, targetId)	{  if (document.getElementById(elemId).checked == true)  {      document.getElementById(targetId).disabled = true;  }   else  {      document.getElementById(targetId).disabled = false;  }	}</script></head><body><input type="checkbox" id="check1" onclick="setState(this.id,'bla')"><input type="text" id="bla"></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...