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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reset single text field

Status
Not open for further replies.

dinoviapangea

Technical User
Apr 9, 2002
41
US
I have multiple text fields in my form like the following,

<Form>
<input type="text" name="text_1"><br>
<input type="text" name="text_2"><br>
<input type="text" name="text_3"><br>
</From>

How can I put a reset button that will reset only that text field? Such as

<Form>
<input type="text" name="text_1"><input type="reset" value="clear"<br>
<input type="text" name="text_2"><input type="reset" value="clear"<br>
<input type="text" name="text_3"><input type="reset" value="clear"<br>
</From>

Thanks,

Dino
 
Like this:

Code:
<form name="f">
<input type="text" name="text_1"><input type="button" value="clear" onclick="this.form.text_1.value = '';"><br />
<input type="text" name="text_2"><input type="button" value="clear" onclick="this.form.text_2.value = '';"><br />
<input type="text" name="text_3"><input type="button" value="clear" onclick="this.form.text_3.value = '';"><br />
</form>

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Works great. One more wrinkle. What if I have the following,

<Form>
<input type="text" name="text_1a"><input type="text" name="text_1b"><input type="reset" value="clear"<br>
<input type="text" name="text_2a"><input type="text" name="text_2b"><input type="reset" value="clear"<br>
<input type="text" name="text_3a"><input type="text" name="text_3b"><input type="reset" value="clear"<br>
</From>

And I want to clear the two fields 1a and 1b?

Thanks,

Dino
 
same as posted above but...

<input type="text" name="text_1"><input type="button" value="clear" onclick="this.form.text_1a.value = '';this.form.text_1b.value = ''"><br />

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 

indeed. of course you'd need the actual field in there.
;)

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Works great. The last wrinkle. How do I use an image instead of a Javascript button?

Thanks,

Dino
 
Code:
<img src="image.gif" onmouseover="this.style.cursor = pointer;" onclick="document.forms['formname'].elements['elem1name'].value=''; document.forms['formname'].elements['elem2name'].value=''; return false;" title="clear" />


How many more "last wrinkles" will there be?

:)

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
sorry, you don't need the onmouseover, it can be like this:

Code:
<img src="image.gif" style="cursor: pointer;" onclick="document.forms['formname'].elements['elem1name'].value=''; document.forms['formname'].elements['elem2name'].value=''; return false;" title="clear" />

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
and another iteration, if you want to have the ability to tab to the image:

Code:
<a href="#" onclick="document.forms['formname'].elements['elem1name'].value=''; document.forms['formname'].elements['elem2name'].value=''; return false;"><img src="image.gif" title="clear" /></a>

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
nice.

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top