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

onclick event to submit a form

Status
Not open for further replies.

aforstie

Programmer
Jun 19, 2006
19
US
I have case where I want to submit a form from a link. I thought I could use the onclick event as seen below to submit the form since it will be within the form.

<a href=" onclick="event.cancelBubble=true;this.form.submit();">

Using FireFox JavaScript console I get an error that reads:t
his.form has no properties

Any ideas what I need to do to get this to work? Thanks in advance!
 
Maybe something like this?

<a href=" onclick='javascript: DoSubmit()'>

Function DoSubmit()
{
event.cancelBubble=true;
document.formname.submit();
}
 
This works for the most part, but I have two more questions.

[1] If I am trying to submit a form when I am not within the form, but it is on the page, how would I do that?

[2] Why would you use return false in place on event.cancelBubble=true?

thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top