From: Greg Scharlemann on
I have the following test page:

<html>
<head>
<script type="text/javascript">
function submitForm() {
alert("here");
return false;
}
</script>
</head>
<body>
<form action="test.html" id="thisForm" name="thisForm"
method="post" onsubmit="return submitForm()">
<input type="text" name="test" value="hello" size="20" />
<a href="javascript:document.thisForm.submit()">Submit</a>
</form>
</body>
</html>

When I click the submit link, the form submits, but it does not hit the
submitForm() method. Any insight into what I have overlooked?
Thanks in advance.

From: Evertjan. on
Greg Scharlemann wrote on 11 nov 2006 in comp.lang.javascript:

> I have the following test page:
>
> <html>
> <head>
> <script type="text/javascript">
> function submitForm() {
> alert("here");
> return false;
>}
> </script>
> </head>
> <body>
> <form action="test.html" id="thisForm" name="thisForm"
> method="post" onsubmit="return submitForm()">
> <input type="text" name="test" value="hello" size="20" />


> <a href="javascript:document.thisForm.submit()">Submit</a>

Use instead:

<input type='submit' value='Submit'>

Using a anchor link is both not invoking the onsubmit,
and is not userfriendly, as one expects a submit button.

==================

btw, if you want to point to a form document.thisForm is not as cross
browser compatible as:

document.forms['thisForm']

or

document.getElementById('thisForm')


> </form>
> </body>
> </html>
>
> When I click the submit link, the form submits, but it does not hit the
> submitForm() method. Any insight into what I have overlooked?
> Thanks in advance.
>
>



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
From: ASM on
Greg Scharlemann a ?crit :
> I have the following test page:
>
> <html>
> <head>
> <script type="text/javascript">
> function submitForm() {
> alert("here");
> return false;
> }
> </script>
> </head>
> <body>
> <form action="test.html" id="thisForm" name="thisForm"
> method="post" onsubmit="return submitForm()">
> <input type="text" name="test" value="hello" size="20" />
> <a href="javascript:document.thisForm.submit()">Submit</a>

<input type="submit" name="send" value="go" />
<a href="javascript:document.thisForm.send.click()">Submit 2</a>

> </form>
> </body>
> </html>
From: Greg Scharlemann on
Thanks to both of you... I've gone with the submit button.

 | 
Pages: 1
Prev: JavaScript Troubles
Next: Constant focus on popup