Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Raleigh, NC
    Posts
    484
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this -

    Code:
    <a href="#" onClick="document.forms[0].media_version_id.value = 0; return false">reset</a>

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Raleigh, NC
    Posts
    484
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the reply mark87 but it doesn't seem to work
    -WebMark Art
    Programming is 80% thinking and 20% spelling

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    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

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    Raleigh, NC
    Posts
    484
    Thanks
    0
    Thanked 0 Times in 0 Posts
    great thanks! That works like a charm
    -WebMark Art
    Programming is 80% thinking and 20% spelling


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •