faqts : Computers : Programming : Languages : JavaScript : Event handling

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

82 of 120 people (68%) answered Yes
Recently 2 of 10 people (20%) answered Yes

Entry

How can I simulate a "submit" button click?

Dec 4th, 2002 19:05
Ryan Buterbaugh, michael greene,


If I know what your are asking, the answer is pretty simple.  The 
submit
() function will submit a form.  Example:
<html>
<body>
<form name="form1" action="yourscript.cgi" method="yourmethod">
<input type="Whatever" etc>
<! more form stuff >
<input type="button" value="Submit" onClick="submittheform();">
</form>
<script language="javascript">
function submittheform() {
document.form1.submit();
}
</script>
</body>
</html>
That's it.  This is useful for checking forms, so that you don't have 
it
submit if the browser detects errors