radio button text box interaction?

liunx

Guest
I'm creating a form and I want an adjacent text box to be usable when a certain radio button is clicked but not when another radio button is selected. The html tutorial I read, while helpful, did not go into how this is done. What I'm trying to do looks something like this:<br />
<br />
<input type="radio" name="number of days" value="single day"><br />
<input type="radio" name="number of days" value="multi day"><br />
<input type="text" name="multi day" value="number of days"><br />
<br />
Anyone know how I get the third input to activate and deactivate depending on which radio button is selected?<br />
<br />
Also is there a way I can specify what values can be entered into the text input and what values cannot? Thanks.<!--content-->Originally posted by Dave Clark <br />
<input type="radio" name="number of days" value="single day"<br />
onclick="this.form.elements['multi day'].value='';<br />
this.form.elements['multi day'].disabled=true;<br />
return true;"> <br />
<input type="radio" name="number of days" value="multi day"<br />
onclick="this.form.elements['multi day'].disabled=false;<br />
this.form.elements['multi day'].value='';<br />
return true;"><br />
<br />
Ok? ;)<br />
<br />
Dave <br />
<br />
Thanks, once again, Dave. I haven't added the code yet (will tomorrow) but I'm sure it'll work.<!--content-->Originally posted by Dave Clark <br />
<input type="radio" name="number of days" value="single day"<br />
onclick="this.form.elements['multi day'].value=''; <br />
this.form.elements['multi day'].disabled=true;<br />
return true;"> <br />
<input type="radio" name="number of days" value="multi day"<br />
onclick="this.form.elements['multi day'].disabled=false;<br />
this.form.elements['multi day'].value='';<br />
return true;"><br />
<br />
Ok? ;)<br />
<br />
Dave <br />
<br />
for anyone else looking to use radio buttons to turn on/off a text box, the above code contains a small error. It should be written as:<br />
<br />
<br />
<input type="radio" name="number of days" <br />
value="single day"<br />
onclick="this.form.elements['multi day'].disabled=true; <br />
this.form.elements['multi day'].value=''; <br />
return true;"> <br />
<input type="radio" name="number of days" <br />
value="multi day"<br />
onclick="this.form.elements['multi day'].disabled=false;<br />
this.form.elements['multi day'].value='';<br />
return true;"><!--content-->Originally posted by Dave Clark <br />
The only change I see is to reverse the order of two JavaScript statements. How does that constitute an error? Seems more a matter of preference.<br />
<br />
Dave <br />
<br />
I guess I shouldn't throw around the word "error" like that. :D <br />
Sorry.<br />
<br />
Anyway, it wasn't a workin' a one way so I'sa did it's another way. :D<!--content-->Originally posted by Dave Clark <br />
Who do you think you are? ...Dobby? :D<br />
<br />
Dave <br />
<br />
Who's Dobby? :confused:<!--content-->Originally posted by Dave Clark <br />
Dobby is an elvish creature in the Harry Potter books/movie and he talks similar to that.<br />
<br />
Dave <br />
<br />
Okay then, I have to stop doing that. :o<!--content-->Ok Dave. Have another one for ya. Looked on internet couldn't find answer. Now I want to tie two radio buttons to three text box inputs labelled "month", "day", and "year". Here's what I have:<br />
<br />
<br />
<INPUT TYPE="radio" NAME="DELIVERY TIME" VALUE="IMMEDIATELY" onclick="this.form.elements['DELIVERY DATE'].disabled=true; this.form.elements['IMMEDIATELY'].value=''; return true;"><br />
<FONT COLOR="#FFFF00" SIZE="3" ID="put"><I><B>IMMEDIATELY</B></I></FONT><br />
<br />
<INPUT TYPE="radio" NAME="DELIVERY TIME" VALUE="SPECIFIED DATE" onclick="this.form.elements['DELIVERY DATE'].disabled=false; this.form.elements['SPECIFIED DATE'].value=''; return false;"><FONT COLOR="#FFFF00" SIZE="3" ID="put"><I><B>SPECIFIED DATE</B></I></FONT><br />
<br />
<FONT COLOR="#FFFF00" SIZE="3" ID="put"><I><B>DATE:</B></I></FONT><FONT COLOR="#FFFF00" SIZE="3" ID="put"><I><B>Month:</B></I></FONT><br />
<br />
<INPUT TYPE="TEXT" NAME="DELIVERY DATE" VALUE="MONTH" SIZE="2"><br />
<br />
<FONT COLOR="#FFFF00" SIZE="3" ID="put"><I><B>Day:</B></I></FONT><br />
<br />
<INPUT TYPE="TEXT" NAME="DELIVERY DATE" VALUE="Day" SIZE="2"><br />
<br />
<FONT COLOR="#FFFF00" SIZE="3" ID="put"><I><B>Year:</B></I></FONT><INPUT TYPE="TEXT" NAME="DELIVERY DATE" VALUE="Year" SIZE="4"><br />
<br />
I'm trying to get all three text boxes {month, day and year} to turn off when the "immediately" radio button is clicked and all three to turn on when the "specified date" radio button is clicked. It works fine if I only include the "month" text box but when I add the two others it fails. I tried renaming each text box "DD1","DD2","DD3" and accounting for that in the "onclick" commands to no avail.<!--content-->Originally posted by Dave Clark <br />
this.form.elements['DELIVERY DATE'][0].disabled=true;<br />
this.form.elements['DELIVERY DATE'][1].disabled=true;<br />
this.form.elements['DELIVERY DATE'][2].disabled=true;<br />
<br />
Dave <br />
<br />
<br />
:o<br />
I'm new to html but somehow I'm embarrassed I didn't know that one. But I appreciate your patience. Thanks for all the help. I think I'm finally out of the worst of it. Well, thats is, until I get to account managers. (sigh)<!--content-->
 
Back
Top