Submit form method does not work

P

Phillip Wu

Hi,

I'm trying to learn Javascript and there is nobody at work that can
assist.
I'm trying to use the submit method of a form when the user clicks on
a anchor.
The example shown is artificial because the real code is too big to
post (it is a pull down menu source I got from the web). The menu
source has to cater for the general case where there are no forms in
the window.

This is the code:
<html>
<head>
<title>Push Me</title>
</head>
<body>
<form action=backend.php method=post name="hostform">
<table>
<tr><td><h5><input type="checkbox" name="record[]"
value="apocws20"></h5></td>
<td><h5>apocws20 </h5></td>
</tr>
<tr><td><h5><input type="checkbox" name="record[]"
value="apocws21"></h5></td>
<td><h5>apocws21 </h5></td>
</tr>
<tr><td><h5><input type="checkbox" name="record[]"
value="apocws22"></h5></td>
<td><h5>apocws22 </h5></td>
</tr>
</table>
<p><a href="altbackend.php" onClick="document.hostform.submit();">
Go to backend</a>
<p><a href="altbackend.php">Go to altbackend</a>
</form>
</body>

I'm expecting that when you click on the link 'Go to Backend' it
should go to
backend.php and when you click on 'Go to altbackend' it should go to
altbackend.php.

What happens is that it always goes to altbackend.php. Note that the
action of the form is backend.php. I have also put a 'return false'
after the submit to tell the browser not to go down the link but the
results are the same.

Why is this so? I have put alerts around the submit call and the
onClick is definitely being called.

Also the following I found on the newsgroup seems to work OK:
<html>
<head>
<title>Test Submit</title>

<script language='JavaScript'>
<!-- HIDE

function submitForm() {
document.myForm.submit()
}

//STOP HIDING -->
</script>

</head>

<body>

<form name='myForm' action='backend.php' method='post'>
<table>
<tr><td><h5><input type="checkbox" name="record[]"
value="apocws20"></h5></td>
<td><h5>apocws20 </h5></td>
</tr>
<tr><td><h5><input type="checkbox" name="record[]"
value="apocws21"></h5></td>
<td><h5>apocws21 </h5></td>
</tr>
<tr><td><h5><input type="checkbox" name="record[]"
value="apocws22"></h5></td>
<td><h5>apocws22 </h5></td>
</tr>
</table>
<a href=javascript:submitForm()>submit</a>
</form>
</body>
</html>

Thanks for any help.
 

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

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,997
Latest member
mileyka

Latest Threads

Top