Jump to content

JavaScript submit Form


Andrew R

Recommended Posts

Hi.  I wrote this script to submit two forms on the one page.  It works in IE and Safari but not in Firefox.  Can anybody see why?  The in error in Firefox is, document.myform is undefined.

<?

	if(isset($_POST['go']))

{				  


////perform other functions here


?>

<form name="myform" method="post" action="test.php" target="_blank"> 
<input name="name" type="hidden" id="name" value="<? echo $_POST['name']; ?>" />
</form> 

<SCRIPT language="JavaScript">

  document.myform.submit();

</SCRIPT> 

<? } ?>

   <form name="contact_form" method="post" action="<? $_SERVER['PHP_SELF']; ?>">



<label>
<textarea name="name" id="name"></textarea>
</label>
<br>
<label>
<input name="go" type="submit" id="go" value="Submit">
</label>
</form>

 

Any help would be much appreciated

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/142837-javascript-submit-form/
Share on other sites

where do i begin :D..... you first need to put your document.myform.submit() in a function; then you can add your other form submit to that same function; something like:

 

<script type="text/javascript">
function submitAll()
{
document.myform.submit();
setTimeout("document.contact_form.submit()", 100);
}
</script>

 

you also may need to add an onsubmit="submitAll(); return false" to both of your forms.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.