...

View Full Version : submitting a form when a link is clicked



heaps21
08-16-2004, 09:41 PM
Hi,
How using Javascript can a form be submitted upon a link being clicked? Or, is this even possble? I hope that is a good enopugh explanation - i couldnt think how else to say it!!

Cheers.

hemebond
08-16-2004, 10:16 PM
<html>
<head>
<title>Submit form on link click</title>
</head>
<body>
<form action="" method="get" id="fm">
<input type="text" name="sub" value="mit">
<a href="" onclick="document.getElementById('fm').submit();return false;">Submit</a>
</form>
</body>
</html>It is always better to use proper form widgets (like a proper submit button), it's what they're there for, and people know their functionality already (so it's a usability thing, and more accessible to other devices).

heaps21
08-17-2004, 06:20 PM
<html>
<head>
<title>Submit form on link click</title>
</head>
<body>
<form action="" method="get" id="fm">
<input type="text" name="sub" value="mit">
<a href="" onclick="document.getElementById('fm').submit();return false;">Submit</a>
</form>
</body>
</html>It is always better to use proper form widgets (like a proper submit button), it's what they're there for, and people know their functionality already (so it's a usability thing, and more accessible to other devices).

Thanks, does the action have to be 'get'? also where do i say the page to send it to, is it in action='' or <a href='' or both?

The reason I have this sort of functinalityis coz i have an ebay style 'matching categories' on my search results page and as far as i could think this was the only way i could successfully do it.

Thanks again.

sad69
08-17-2004, 07:55 PM
Well the method doesn't have to be GET, it could be POST.

And the page you want to submit to would be the specified in the ACTION attribute of the FORM tag.

Happy coding!
Sadiq.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum