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!

1 comment:

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

    ReplyDelete