faqts : Computers : Programming : Languages : JavaScript : Forms : Checkboxes

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

61 of 77 people (79%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I use a check box to toggle an input field between readonly(grey bg color) and editable?

Aug 21st, 2005 10:23
Javier Chapa, Arsen Yeremin, Mihir Shah,


<html>
<head>
	<title>CheckMe</title>
</head>
<body>
<form>
  <p style="line-height: half">
  <input type="checkbox" onclick=GrayOut(this)>
	Utility Check </p>
	<p style="line-height: none">
  <font size="2">         City 
of : </font>
  <input type="text" name="first_name" value="" disabled="disabled" 
size="20" style="padding: 0"><font size="2">
	</font> </p>
	<p style="line-height: "1"> </p>
	<p> <!  <input type="text" name="first_name" 
value="Arsen">       
	</p>
</form>
<script>
function GrayOut(obj_checkbox)
{
  if(obj_checkbox.checked)
  {
    obj_checkbox.form.first_name.disabled = false;
  }
  else
  {
    obj_checkbox.form.first_name.disabled = true;  
  }
}
</script>