Page 1 of 1

JavaScript Auto Submit Form

Posted: Tue Aug 04, 2009 9:12 pm
by sysout
<html>
<head>
<script language="JavaScript" type="text/javascript">
var t = setTimeout("document.myform.submit();",2000); //2 seconds measured in miliseconds
</script>
</head>
<body>
<form name="myform" action="nextpage.html" method="post">
</form>
</body>
</html>
That code works perfect..

But, I wanna make an auto submit form with onClick button..it doesn't work :(
<html>
<head>
<script language="JavaScript" type="text/javascript">
var t = setTimeout("document.myform.submit();",2000); //2 seconds measured in miliseconds
</script>
</head>
<body>
<form name="myform" action="nextpage.html" method="post">
<input type="name" size="12" maxlength="6" id="pswd" />
<input type="Submit" value="LOGIN" name="value(Submit)" onclick="javascript:return Login_Form_Validator(document.parameter)" onmouseover="this.style.cursor='hand'"/>
</form>
</body>
</html>
it doesn't work anymore just because of this code :
<input type="Submit" value="LOGIN" name="value(Submit)" onclick="javascript:return Login_Form_Validator(document.parameter)" onmouseover="this.style.cursor='hand'"/>
if I delete this code, it works perfectly

Can Anyone help me to solve this? thanks palz

Re: JavaScript Auto Submit Form

Posted: Wed Aug 05, 2009 1:09 pm
by kaszu
You don't need "javascript:" there
onclick="javascript:return Login_Form_Validator(document.parameter)"
Also don't add validation to the button, but add it to the form onsubmit event, because if user will press return key while focused on other input form form will submit without validation.

Code: Select all

<form name="myform" action="nextpage.html" method="post" onsubmit="return Login_Form_Validator(document.parameter);">