Javascript – HTML Form Submission

Submitting a HTML form in Javascript can be done by just one line.

document.forms["<form_name>"].submit();
//or
document.<form_name>.submit();

 
 

Example:
Assume if you have a HTML form with id and name as myform.

form.html

<script type="text/javascript">
        function submitform() {
                document.myform.submit();
                //document.forms["myform"].submit();
        }
</script>
<form method="POST" name="myform" action="search.php">
        What is your name?<br/>
        <input type="text" name="visitor_name" /><br/>
        <a href="javascript: submitform()">Click me</a>
</form>

 

Also create the search.php

hello <?php echo $_POST["visitor_name"]; ?> !

 

Try it out~

 

Reference: How to Submit a Form Using JavaScript

Done =)

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.