View Full Version : RESET problem
Alias
11-06-2002, 02:48 PM
Hello
I find that it is possible to use text or an image as a submit button:
<a href="javascript:document.theFormName.submit();">Submit</a>
Is it possible to use text or an image as a RESET button ???
When I try:
document.theFormName.reset();
it doesn't work.
Dr. Web
11-06-2002, 03:23 PM
<a href="#" onClick="document.formName.reset()">reset</a>
<a href="#" onClick="document.formName.reset()"><image src="reset.gif"></a>
<input type=image src="reset.gif" onClick="document.formName.reset()"> (for IE 5.0)
Jon Hanlon
11-06-2002, 05:40 PM
When you say:
href=....
This means 'take me to page called ....'.
This works OK when you are submitting (as the submit action generates new content), but won't work for other things.
Do as the Doc says, and put your action in an onclick handler (although you should always return false from such trickery).
<a href="#" onClick="document.formName.reset();return false">reset</a>
<a href="#" onClick="document.formName.reset();return false"><image src="reset.gif"></a>
<img src="reset.gif" onClick="document.formName.reset();return false"> (for IE 5.0)
kdjoergensen
11-06-2002, 05:42 PM
The reason your reset function does not work, but submit works, is that the page actually navigates away from it's current url on submit. however, on reset the url stays, but the href tag will navigate to a return value (or if no return value an empty page comes up). What you need to do, is to provide a 'false' return value.
You can do as Dr. Web did and use the hash (#) value which will in effect reload the page, but add a "#" sign at the end of the ulr (look at your address bar and you will see), or you can do this:
<a href="javascript: document.formName.reset(); return false;">Reset</a>
or
<a href="javascript: void(0)" onclick="document.formName.reset()">Reset</a>
Good luck
Alias
11-06-2002, 07:10 PM
Thanx friends :D
You helped me so much :)
Best Regards
Dr. Web
11-07-2002, 12:18 PM
So, KD... John:
collectively what would you suggest out of the:
<a href="#" onclick="doThis(); return false">blah</a>
or
<a href="javascript: void(0)" onclick="document.formName.reset()">Reset</a>
Jon Hanlon
11-07-2002, 04:44 PM
The first way's better if you ask me.
The javascript:void(0) business was mainly to get around Netscape's poor Document Object Model.
What you want to do is cancel the event before it hits the href, as the href will try to navigate away. This means, for instance, that onbeforeunload events will fire, even though you're not going anywhere.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.