Javascipt Submit Forms

No need to click those submit buttons

Sometimes you need Javascript to submit the form automatically without the user having to click on anything. To do so, you would use the following code.

NOTE: These functions use the getObject() function that I have described on the previous page. If you do not include this function in your script, the code will not work at all and will return an error.

function submitForm(el) {
     getObject(el).submit();
}

To use this code on the page, you would set up you page like the sample below:

<html>
<head>
<script type="text/javascript">
   function getObject(el) {
     return document.all ? document.all[el] : document.getElementById(el);
   }

   function submitForm(el) {
     getObject(el).submit();
   }
</script> </head>
<body>

<form action="#" method="post" name="Test" id="Test">
   <input type="radio" name="Radio1" id="Radio1" value="Test" onclick="javascript:submitForm('Test');" />
</form>

</body>
</html>

Javascript

Ads