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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.