How do I enable textfield based on radio button choice?
Posted: Thu Aug 12, 2010 4:33 am
Can this be done in PHP?
Ive already search it in the web but I dont understand how to do it so I was hoping you guys would explain.
Here are the things I dont understand
1: var currentEnabled = null; - why was it set to null?
2: Im confused about the syntax currentEnabled.disabled = true.
3: currentEnabled = elem
4: How do I modify the code or create a new one (preferred) so that a single radio button can control more than 1 textfield?
Ive already search it in the web but I dont understand how to do it so I was hoping you guys would explain.
Here are the things I dont understand
1: var currentEnabled = null; - why was it set to null?
2: Im confused about the syntax currentEnabled.disabled = true.
3: currentEnabled = elem
4: How do I modify the code or create a new one (preferred) so that a single radio button can control more than 1 textfield?
Code: Select all
<script type="text/javascript">
var currentEnabled = null;
function enableElement(elem)
{
if (currentEnabled)
{
currentEnabled.disabled = true;
}
elem.disabled = false;
currentEnabled = elem;
}
</script>
<form action="">
<input type="text" name="inp1" disabled="disabled">
<input type="radio" name="sel" value="1"
onclick="enableElement(this.form.elements['inp1']);">
<br>
<input type="text" name="inp2" disabled="disabled">
<input type="radio" name="sel" value="2"
onclick="enableElement(this.form.elements['inp2']);">
<br>
<input type="text" name="inp3" disabled="disabled">
<input type="radio" name="sel" value="3"
onclick="enableElement(this.form.elements[inp3'']);">
</form>