Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-25-2005, 05:29 PM   PM User | #1
webmarkart
Regular Coder

 
Join Date: Jul 2002
Location: Raleigh, NC
Posts: 484
Thanks: 0
Thanked 0 Times in 0 Posts
webmarkart is an unknown quantity at this point
Resetting a single form field

I cannot believe how much this little thing is causing me such a headache...

I have a small form and I want to have a link (or button if needed) to reset a single select field.

This is what I have but it's not working - I left out the other fields of the form just to simplify things.

Code:
	<form name="ImageMediaMgrForm" action="/admin-bin/pubsys/imagemediamgr.cgi?i_id=60;nmf_rpoint=" method="post" enctype="multipart/form-data">
	<input type="hidden" name="mode" value="save_add">
	<input type="hidden" name="prev_mode" value="add">
	<input type="hidden" name="id" value="">
	<input type="hidden" name="i_id" value="60">
	
	<table width="80%" border="0" cellpadding="2" cellspacing="1" align="center">
	<tr class="nesttable">
		<td class="fielddesc">&nbsp;Skip These Media Versions:</td>
		<td>
            <select name="media_version_id" size="3" multiple >
               <option value="1">Highlight</option>
               <option value="2">Embedded</option>
               <option value="3">Standalone</option>
            </select>
            <a href="#" onClick="document.ImageMediaMgrForm.media_version_id.selected==0">reset</a></td>
	</tr>
	<tr>

		<td colspan="2" class="center">
			<input type="submit" name="submit" value="Submit" class="frmbutton">
			<input type="button" name="cancel" value="Cancel" onClick="document.location='?i_id=60;mode=search_results'" class="frmbutton">
		</td>
	</tr>
	</table>
__________________
-WebMark Art
Programming is 80% thinking and 20% spelling
webmarkart is offline   Reply With Quote
Old 05-25-2005, 05:54 PM   PM User | #2
mark87
Senior Coder

 
Join Date: Dec 2004
Location: Essex, UK
Posts: 2,636
Thanks: 0
Thanked 0 Times in 0 Posts
mark87 is on a distinguished road
Try this -

Code:
<a href="#" onClick="document.forms[0].media_version_id.value = 0; return false">reset</a>
mark87 is offline   Reply With Quote
Old 05-25-2005, 06:52 PM   PM User | #3
webmarkart
Regular Coder

 
Join Date: Jul 2002
Location: Raleigh, NC
Posts: 484
Thanks: 0
Thanked 0 Times in 0 Posts
webmarkart is an unknown quantity at this point
thanks for the reply mark87 but it doesn't seem to work
__________________
-WebMark Art
Programming is 80% thinking and 20% spelling
webmarkart is offline   Reply With Quote
Old 05-25-2005, 07:45 PM   PM User | #4
Bill Posters
Senior Coder

 
Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
Bill Posters will become famous soon enough
e.g.
Code:
function clearOptions() {
	if (!document.getElementsByTagName) return;
	var options = document.getElementById('media_version_id').getElementsByTagName("option"), 
	oLength = options.length;
	for(var i=0; i < oLength; i++) {
		options[i].selected = false;
	}
}
Code:
<select name="media_version_id" id="media_version_id" size="3" multiple="multiple">
	<option value="1">Highlight</option>
	<option value="2">Embedded</option>
	<option value="3">Standalone</option>
</select>

…

<a href="#" onclick="clearOptions(); return false;">Clear options</a>
Note that the name attribute of the select element has also been used for the id attribute.


What this does is find all the option elements within an element with id="media_version_id" and changes each of their selected attributes to false (unselected).

hth
Bill Posters is offline   Reply With Quote
Old 05-25-2005, 08:04 PM   PM User | #5
webmarkart
Regular Coder

 
Join Date: Jul 2002
Location: Raleigh, NC
Posts: 484
Thanks: 0
Thanked 0 Times in 0 Posts
webmarkart is an unknown quantity at this point
great thanks! That works like a charm
__________________
-WebMark Art
Programming is 80% thinking and 20% spelling
webmarkart is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:23 AM.


Advertisement
Log in to turn off these ads.