Submit a HTML Form using a Hyperlink

A user asked me recently on the forums if it was possible to Submit an HTML form without the Submit button. She wanted to do it using a Hyperlink instead.

Well it is possible to submit the form using a hyperlink with a small amount of JavaScript code as shown here:

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Submit A HTML Form using a Hyperlink</title>

<
script type="text/javascript">
function
frmSubmit() {
document.form1.submit();
}
</script>
</
head>

<
body>
<
form name="form1" method="post" action="somescript.pl" >
<
div>
<
a href="javascript:frmSubmit();">Submit</a>
</
div>
</
form>
</
body>
That’s all you need!




About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

1 comment:

fixy32 said...

I was trying it out on ASP.NET form and face error