CancelImage Upload

How to submit a form via a link with JavaScript

The standard HTML form submit button is all well and good. But as soon as you start working on more complex web applications you will probably sooner, rather than later, require a JavaScript function via which a specified form can be submitted. Here then is just that function:

javascript:document.getElementById('form1').submit();

As you can see the specified form1 is accessed via getElementById(), and then submitted with the function submit(). Here is an example of how this code can be used in practice:

<html>
<head>
<title>How to submit a form via a link with JavaScript</title>
</head>
<body>

<form id="form1">
Title: <input type="text"><br>
Text: <textarea></textarea><br>
</form>

<a href="javascript:document.getElementById('form1').submit();">Submit Form1</a>

</body>
</html>


Login
Want to leave a comment?

No problem. Just enter your email and password below.


register | home | reminder

myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com