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

onsubmit event and .submit() function not the same?

Status
Not open for further replies.

progman1010

Programmer
Jan 2, 2008
108
US
i have a script in which a button's onclick action submits a form: document.formname.submit(); but I also need to add an onsubmit='' action to the form itself. however, the button seems to supercede the form event and i can't get it to work. any ideas?

Code:
function progress_submit(id,formie) {
	document.getElementById(id).innerHTML='<img src=\'/images/ani_progress2.gif\' style=\'margin-left: 10px;\'>'
	document.getElementById(formie).submit();
}

<form action="<?=$action?>" method="post" name="formie" id='formie' onSubmit="return validate();">

<p style="float:left;" id="progress1">
	<input type="button" class="button" value="Next &gt;" onclick="progress_submit('progress1','formie');"/>
</p>
</form>

Specifically, the page is skipping the validate() function, which works fine when i click on an actual submit button (type=submit), but not through the code as shown above.
 
If the validate() follows the common practice of returning false for the case validation fail, it can be realized like this.
[tt]
function progress_submit(id,formie) {
document.getElementById(id).innerHTML='<img src=\'/images/ani_progress2.gif\' style=\'margin-left: 10px;\'>'
[blue]var b=document.getElementById(formie).onsubmit();
if (b) {[/blue]
document.getElementById(formie).submit();
[blue]}[/blue]
}[/tt]
 
that's true. i wasn't looking at it from that angle...

works like a charm!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top