Submitting Form without Using Submit button in JavaScript
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>
|





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
nice tutorial, what i am looking for! thanks for sharing great tutor.
hmmm good example dude….
thanks sir, this tutorial is really helpful for those who wants to submit form without submit button..thanks again..
nice .. this is really helpfull.
good