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!

Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 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