Submitting Form without Using Submit button in JavaScript

By | 02/06/2012

Forms in website are used to submit values to the server or to give query or to request some thing. Every form will have  a submit button, which is clicked after finishing filling up of form values. After clicked the submit button only form values are get processed. In some instance there many be situation to submit form values without using buttons. This problem can be achieved by java script.

READ ALSO:

Submit Form Without Submit Button, When Drop-down List box is Selected

Submit Form Without Submit Button, When Radio Button is Clicked

document.forms["FormName"].submit();  is used to submit the form values.

Here we are using anchor tag i.e. link to work as submit button. When link is clicked, it will call java script function, within java script function  document.forms["myform"].submit(); will be used to auto submit the form values.

Instead of using document.forms["FormName"].submit(); function, we can also use   document.getElementById(“myform”).submit();

1
2
3
4
5
6
<script type="text/javascript">
function formSubmit()
{
document.getElementById("frm1").submit();
}
</script>

Note:  document.FormName.submit(); function doesn’t work to submit values.

 

index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<html>

<head>
Submit Form without Submit button
</head>
<body>
<script type="text/javascript">
function submitform()
{
document.forms["myform"].submit();
alert("Value is sumitted");
}
</script>
<form id="myform" action="submit.php" method="post">
Search: <input type="text" name="query">
<a href="javascript: submitform()">Submit</a>
</form>
</body>
</html>

After auto submitting the values, value which is entered will be shown in submit.php page.

submit.php

1
2
3
4
5
6
7
8
<html>
<body>
<?php
$a=$_POST['query'];
echo "Submitted values is ".$a;
?>
</body>
</html>
prasad

About prasad

Prasad K has written 111 post in this blog.

6 thoughts on “Submitting Form without Using Submit button in JavaScript

  1. Shahbaz Ahmed Bhatti

    can u please make a live exmaple or can u please uplaod a exmaple script so i can see hwo ot do that job without submit button

    Thanks

    Reply
  2. Tahir

    nice tutorial, what i am looking for! thanks for sharing great tutor.

    Reply
  3. Gurdeep Singh

    thanks sir, this tutorial is really helpful for those who wants to submit form without submit button..thanks again..

    Reply