B
bill
Is there any way to make a link (as marked by an <A>-tag, that is),
behave exactly like a submit button?
Many thanks!
-bill
behave exactly like a submit button?
Many thanks!
-bill
Yes, but only if you're sure that js is enabled.bill said:Is there any way to make a link (as marked by an <A>-tag, that is),
behave exactly like a submit button?
Many thanks!
-bill
Yes, but only if you're sure that js is enabled.
<a href="NoJSPage.html"
onclick="this.href='#';document.formName.submit();">Click</a>
If you have a form verification function:
<a href="NoJSPage.html"
onclick="this.href='#';if(verify(document.formName))
{document.formName.submit();}">Click</a>
Lee said:Mick White said:
Rather than setting the href value in the onclick handler,
simply have the onclick handler return false. That will
prevent the link from being followed. Failing to return
false may cause the submit to fail, since the browser is
being told to load the page specified by the action and
to reload the current page (href="#"), simultaneously.
Without this.href="#", a return of "true" might load the non js page, no?
Lee said:Mick White said:
Sure, so you simply return false:
onclick="if(verify(document.formName)){document.formName.submit()};return false"
Mick said:I thought that a return "false" might cancel the submission, of course I
would probably be wrong.
Thanks, Lee.
Mick
Grant said:Mick White wrote: :
Returning false from any event handler should, and usually does, stop the element's
default behaviour that triggered the event. It is not specifically related to forms.
Examples for "return false;":
Returning false to the onsubmit event of a <form ...> prevents form submission because
the submission of the form was the triggered event.
Returning false to the onclick event of an <input type="submit" ...> prevents form
submission, but only because it stops the "click" of the submit button, which prevents
the submission.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.