bill wrote:
[color=blue]
> 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
>[/color]
Yes, but only if you're sure that js is enabled.
<a href="NoJSPage. html"
onclick="this.h ref='#';documen t.formName.subm it();">Click</a>
If you have a form verification function:
<a href="NoJSPage. html"
onclick="this.h ref='#';if(veri fy(document.for mName))
{document.formN ame.submit();}" >Click</a>
Mick White said:[color=blue]
>
>bill wrote:
>[color=green]
>> 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
>>[/color]
> Yes, but only if you're sure that js is enabled.
><a href="NoJSPage. html"
>onclick="this. href='#';docume nt.formName.sub mit();">Click</a>
>
>If you have a form verification function:
><a href="NoJSPage. html"
>onclick="this. href='#';if(ver ify(document.fo rmName))
>{document.form Name.submit();} ">Click</a>[/color]
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.
Lee wrote:
[color=blue]
> Mick White said:
>[color=green]
>>bill wrote:
>>
>>[color=darkred]
>>>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
>>>[/color]
>>
>> Yes, but only if you're sure that js is enabled.
>><a href="NoJSPage. html"
>>onclick="this .href='#';docum ent.formName.su bmit();">Click</a>
>>
>>If you have a form verification function:
>><a href="NoJSPage. html"
>>onclick="this .href='#';if(ve rify(document.f ormName))
>>{document.for mName.submit(); }">Click</a>[/color]
>
>
> 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.[/color]
Without this.href="#", a return of "true" might load the non js page, no?
Mick[color=blue]
>[/color]
Mick White said:[color=blue]
>
>Lee wrote:
>[color=green]
>> Mick White said:
>>[color=darkred]
>>>bill wrote:
>>>
>>>
>>>>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="thi s.href='#';docu ment.formName.s ubmit();">Click </a>
>>>
>>>If you have a form verification function:
>>><a href="NoJSPage. html"
>>>onclick="thi s.href='#';if(v erify(document. formName))
>>>{document.fo rmName.submit() ;}">Click</a>[/color]
>>
>>
>> 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.[/color]
>
>Without this.href="#", a return of "true" might load the non js page, no?[/color]
Mick White wrote:
[color=blue]
> Lee wrote:
>[color=green]
> > Mick White said:
> >[color=darkred]
> >>Lee wrote:[/color][/color]
>[color=green][color=darkred]
> >>
> >>Without this.href="#", a return of "true" might load the non js page, no?[/color]
> >
> >
> > Sure, so you simply return false:
> >
> > onclick="if(ver ify(document.fo rmName)){docume nt.formName.sub mit()};return false"
> >[/color]
>
> I thought that a return "false" might cancel the submission, of course I
> would probably be wrong.
> Thanks, Lee.
> Mick[/color]
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.
Returning false to the onclick event of an <a ...> stops the "click" of the link, so
the href attribute never gets followed.
Returning false to the onkeydown event of <input type="text" ...> prevents the key
that was pressed down from appearing in the input.
--
Grant Wagner <gwagner@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq
Grant Wagner wrote:
[color=blue]
> Mick White wrote:[/color]
:[color=blue][color=green][color=darkred]
>>>
>>>onclick="if( verify(document .formName)){doc ument.formName. submit()};retur n false"
>>>[/color]
>>
>>I thought that a return "false" might cancel the submission, of course I
>>would probably be wrong.
>>Thanks, Lee.
>>Mick[/color]
>
>
> 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.[/color]
If I remove [this.href="#" ], and add "return false", the original link
is followed, without form submission (as you suggest).
The form works as it should @
Try it.
Mick
[color=blue]
>
> Returning false to the onclick event of an <a ...> stops the "click" of the link, so
> the href attribute never gets followed.
>
> Returning false to the onkeydown event of <input type="text" ...> prevents the key
> that was pressed down from appearing in the input.
>
> --
> Grant Wagner <gwagner@agrico reunited.com>
> comp.lang.javas cript FAQ - http://jibbering.com/faq
>
>[/color]
Comment