PDA

View Full Version : JavaScript Auto Submit Form



sysout
08-05-2009, 02:32 AM
<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

prasanthmj
08-05-2009, 11:23 AM
Why is it named 'value(Submit)'? can it be just 'submit' or 'login'?

Try:


onsubmit="javascript:return Login_Form_Validator(document.parameter)

Also see: How to Submit a Form Using JavaScript:

javascript-coder.com/javascript-form/javascript-form-submit.phtml

Moderator's Note:
Although essentially correct, the advice at that link is confusing as it first mentions id to identify the form, then later shows the more cross browser method involving name. It gets worse if you're trying to validate to HTML 5 though. But that's another story.

sysout
08-08-2009, 10:02 AM
still don't work palz..
I have change it to onsubmit..haiz

tazosmr
01-24-2013, 02:38 PM
the form should be inserted inside body, and script can be execution body. so when page is loaded, it will be immediately executed:


<html><head></head>

<body>

<form action="page.php" method="post">
<input type="text" name="example1" value="blabla" />
<input type="submit" />
</form>


</body>
<SCRIPT LANGUAGE=JavaScript>document.forms[0].submit();</SCRIPT>
</html>

Here is a working auto-submit method: when page is loaded, it will the form will be immediately autosubmited (the values can be set with php variables).


<form action="page.php" method="post">
<input type="text" name="example1" value="<?php echo $_POST['something1'];?>" />
<input type="text" name="example2" value="ANOTHER_YOUR_VALUE" />
<input type="submit" />
</form>

<SCRIPT LANGUAGE="JavaScript">document.forms[0].submit();</SCRIPT>


for example, the $_POST['something1'] value is received from the previous real-user submited Form, and this form can add another input with ANOTHER_YOUR_VALUE.