PDA

Click to See Complete Forum and Search --> : How can I get my "onsubmit" functions to be executed?


Oct 5th, 2000, 04:17 AM
Hi!

I have this form on my page, with an "onsubmit" function". Now I don't use a submit button to have the form submitted, but an image. So the code goes something like this (the file validationfunctions.js contains a function called validatecontents() ):


<script language="javascript">
<!--
function submittheform()
{
document.myform.submit();
}
//-->
</script>
<script language="javascript" src="validationfunctions.js">
</script>
.
.
<form name = "myform" action="nextpage.asp" onsubmit="validatecontents()">
.
.
<a href="javascript:submittheform()"><img src="image.jpg"></a>
</form>


Now when I click the image, it submits the form, without running the validatecontents-function first. Why? And how can I make it so it DOES run that function first?

Many thanx! :)

msdnexpert
Oct 5th, 2000, 07:13 AM
try this
<form name = "myform" action="nextpage.asp" OnSubmit="return validatecontents()">

Also return true from the function validatecontents()

Oct 5th, 2000, 08:52 AM
Hi!

I'm sorry, in my page the form declaration is like the solution you gave, but when submitting the problem here, I just typed the code in from heart, and forgot to type the return statement. :)

So... the problem remains unsolved..

monte96
Oct 5th, 2000, 10:08 AM
Why not call the validation function from your submittheform() function?