Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to reset an individual form element?

Status
Not open for further replies.

axsom1

Technical User
Feb 27, 2001
67
US
I have an application that uses a single form but uses DIV tags to display different sections with tabs.

I would like to be able to clear only certain form elements when they click on a different radio button.

Below is a little snippet of what I have:

Code:
<tr>
    <td style="border-right: 1px solid black;" width="15%"><input name="1" type="radio" value="" checked onClick="return showRecurrence('sh_single');">Single Event<br>
	<input name="1" type="radio" value="" onClick="return showRecurrence('sh_daily');">Daily<br>
	<input name="1" type="radio" value="" onClick="return showRecurrence('sh_weekly');">Weekly<br>
	<input name="1" type="radio" value="" onClick="return showRecurrence('sh_monthly');">Monthly<br>
	<input name="1" type="radio" value="" onClick="return showRecurrence('sh_yearly');">Yearly
	</td>
	<td valign="top">
	
	<div id="singler" style="display:;">
	&nbsp;
	</div>
	
	<div id="dailyr" style="display: none;">
	<input name="1a" type="radio" value="">Every <input type="text" size="5"> day(s)<br>
	<input name="1a" type="radio" value="">Every WeekDay (M-F)
	</div>
	
	<div id="weeklyr" style="display: none;">
	Recur every <input type="text" size="5"> week(s) on:<br>
	<input type="checkbox"> Sun&nbsp;&nbsp;	<input type="checkbox"> Mon&nbsp;&nbsp;	<input type="checkbox"> Tue&nbsp;&nbsp;	<input type="checkbox"> Wed<br>
	<input type="checkbox"> Thu&nbsp;&nbsp;	<input type="checkbox"> Fri&nbsp;&nbsp;	<input type="checkbox"> Sat
	</div>
	
	<div id="monthlyr" style="display: none;">
	<input name="1b" type="radio" value="">Day <input type="text" size="5"> every <input type="text" size="5"> month(s)<br>
	<input name="1b" type="radio" value="">The 
	<select>
	<option selected></option>
	<option>First</option>
	<option>Second</option>
	<option>Third</option>
	<option>Fourth</option>
	<option>Last</option>
	</select> 
	<select>
	<option selected></option>
	<option>Sunday</option>
	<option>Monday</option>
	<option>Tuesday</option>
	<option>Wednesday</option>
	<option>Thursday</option>
	<option>Friday</option>
	<option>Saturday</option>
	</select> 
	every <input type="text" size="5"> month(s)	
	</div>
	
	<div id="yearlyr" style="display: none;">
	<input name="1c" type="radio" value="">Every  
	<select>
	<option>January</option>
	</select> 
	<input type="text" size="5"><br>
	<input name="1c" type="radio" value="">The 
	<select>
	<option selected></option>
	<option>First</option>
	<option>Second</option>
	<option>Third</option>
	<option>Fourth</option>
	<option>Last</option>
	</select> 
	<select>
	<option selected></option>
	<option>Sunday</option>
	<option>Monday</option>
	<option>Tuesday</option>
	<option>Wednesday</option>
	<option>Thursday</option>
	<option>Friday</option>
	<option>Saturday</option>
	</select> 
	of 
	<select>
	<option>January</option>
	</select>
	</div>
	
	</td>
  </tr>

So basically what I want to do, is when I select any of the radio buttons from group 1, I would like to reset those form elements back to default or nothing.

Is this possible in Javascript, or am I going to need to do some processing on the server based on which radio button in actually selected?

Any suggestions to accomplish this in a better way?

Any help is appreciated.

Thanks,
John
 

>> when I select any of the radio buttons from group 1

Where is group 1 defined? I can't find it anywhere.

And why do you have this: style="display:;" ?

Dan


 
Something that works for me in IE6 when I need something like this is to create an attribute in whatever tags I might need to reset. I might name the attribute 'original'.

For example:

Code:
<input name='userName' type='text' original='John Smith' value='John Smith' />

Then, if the user changes the value, you can reset the value in javascript with:

Code:
formName.userName.value = formName.userName.original;

There are variations on this idea you can come up with for radio buttons (using a hidden form element to save the original value) or a select list (saving the default index as the 'original' attribute in the select tag), but this is the basic idea.

'hope this helps.

--Dave
 
Dan,

The group 1 radio buttons are those with the name="1" buttons.

I have the display:; set because when I click on the radio button, it launches some code that changes the display status of the div tags. This one is not set as it is the default.

Thanks,
John
 
Dave,

I will try what you suggested...I will let you know what I find out.

Thanks for the help.
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top