Enable Textbox when radio button selected

T

teddy.am

Guys,

I have a set of 6 radio buttons, infront of each one there's a textbox
....
i need all textboxes disabled .... once one of the radio buttons is
selected, the texbox infront of it will be anabled to type in ...

any fast solution?
 
L

Lasse Reichstein Nielsen

I have a set of 6 radio buttons, infront of each one there's a textbox
...
i need all textboxes disabled .... once one of the radio buttons is
selected, the texbox infront of it will be anabled to type in ...

----
<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>
----

You might want to have the textboxes enabled by default and use
a script to disable them. Then they still work if Javascript is
disabled.

Good luck.
/L
 
T

teddy.am

Thumbs up,
Thanks a bunch

I have a set of 6 radio buttons, infront of each one there's a textbox
...
i need all textboxes disabled .... once one of the radio buttons is
selected, the texbox infront of it will be anabled to type in ...

----
<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>
----

You might want to have the textboxes enabled by default and use
a script to disable them. Then they still work if Javascript is
disabled.

Good luck.
/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top