submit form with javascript

G

Greg Scharlemann

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.
 
E

Evertjan.

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')
 
A

ASM

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" />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top