Jump to content

[SOLVED] document.form.submit()? submission failing :(


flappy_warbucks

Recommended Posts

Ok right, i have to do this thing and bear with me cos i am a total newbie with Javascript.

 

OK so far i thinki have done quite well to get as far as i have but this one thing just stops me dead in my tracks.

 

So what i want is:

 

a form that comes up in a popup (child) window, data is entered, when a button is pressed on the child form, the dataa is passed to the main (parent) window and the form automaticly submitted.

 

let me show you what i done so far:

 

<!--
function return_form()
{
	opener.document.my_form.text_field.value = document.test.text_box.value;
	if (document.test.check.checked)
	{
		alert("true");
		opener.document.my_form.check.checked = true;
		opener.document.my_form.hidden.value = true;
	}
	else
	{
		alert("False");
		opener.document.my_form.check.checked = false;
		opener.document.my_form.hidden.value = false;
	}
	opener.document.my_form.submit();
//	window.close();
	return false;
}
-->

 

Now i can get the data sent back no problems that all works fine but i cannot get the damn thing to submit at the same time, this is proving to be a bit of a headace.. hopefully someone can tell me where i am going wrong?

 

thankys :)

Link to comment
Share on other sites

Can you post your HTML form too? I don't see any immediate problem, unless you haven't defined the variable 'my_form'...

 

Opps sowie :)

 

OK this is the index.php (parent) page that calls test.php (child) page.

 

<?PHP
IF (!isset($_POST['sub']))
{
	start();
}
else
{
	cont();
}
function start()
{
?>
<html>
<head>
<title>returniung crap init</title>
<script language="javascript">
	function trial()
	{
		open('test.php','my_window', 'height=200,width=200');
	}
</script>
</head>
<body>
<form name="my_form" method="post" action="<?php ECHO $_SERVER['PHP_SELF'];?>">
<input type="hidden" name="hidden">
<input name="sub" value="1" type="hidden">
<p><input type="text" name="text_field">
<p><input type="checkbox" name="check">
<p><input type="button" value="Continue" name="submit" onClick="javascript:trial()">
</body>
</html>
<?php
}
function cont()
{
foreach($_POST as $k=>$v)
{
	echo "$k=>$v<br>";
}
}

 

and this is the test page that is called by the index (parent) page.

 

<html>
<head>
<title>the other page</title>
<script language="javascript">
<!--
function return_form()
{
	opener.document.my_form.text_field.value = document.test.text_box.value;
	if (document.test.check.checked)
	{
		alert("true");
		opener.document.my_form.check.checked = true;
		opener.document.my_form.hidden.value = true;
	}
	else
	{
		alert("False");
		opener.document.my_form.check.checked = false;
		opener.document.my_form.hidden.value = false;
	}
//		opener.document.my_form.submit();
	window.close();
	return false;
}
-->
</script>
</head>
<body>
<form name="test" onSubmit="return_form(); return false;">
<input type="text" name="text_box" size="20">
<input type="checkbox" name="check">
<input type="submit" value="OK">
</form>
</body>
</html>

 

thankys :)

Link to comment
Share on other sites

Here's my code (it seems to do what you want):

{index.php}

<?PHP
IF (!isset($_POST['sub']))
{
	start();
}
else
{
	cont();
}
function start()
{
?>
<html>
<head>
<title>returniung crap init</title>
<script language="javascript">
	var done = false;
	var t;
	function trial() {
		open('test.php','my_window', 'height=200,width=200');
		t = setInterval('if(done) subm()', 500);
	}
	function subm() {
		clearInterval(t);
		document.my_form.submit();
	}
</script>
</head>
<body>
<form name="my_form" method="post" action="<?php ECHO 

$_SERVER['PHP_SELF'];?>">
<input type="hidden" name="hidden">
<input name="sub" value="1" type="hidden">
<p><input type="text" name="text_field">
<p><input type="checkbox" name="check">
<p><input type="button" value="Continue" name="submit2" 

onClick="javascript:trial()">
</body>
</html>
<?php
}
function cont()
{
foreach($_POST as $k=>$v)
{
	echo "$k=>$v<br>";
}
}
?>

 

{test.php}

<html>
<head>
<title>the other page</title>
<script language="javascript">
<!--
function return_form()
{
	opener.document.my_form.text_field.value = 

document.test.text_box.value;
	if (document.test.check.checked)
	{
		//alert("true");
		opener.document.my_form.check.checked = true;
		opener.document.my_form.hidden.value = true;
	}
	else
	{
		//alert("False");
		opener.document.my_form.check.checked = false;
		opener.document.my_form.hidden.value = false;
	}
	//opener.document.my_form.submit();
                opener.done=true;
	window.close();
	return false;
}
-->
</script>
</head>
<body>
<form name="test" onSubmit="return_form(); return false;">
<input type="text" name="text_box" size="20">
<input type="checkbox" name="check">
<input type="submit" value="OK">
</form>
</body>
</html>

 

The way it works is that when the form in the child window is submitted, the JS changes a variable in the parent window. Then the parent window checks if that variable has been changed twice every second, and if it has, it submits its own form (the one in the parent window).

 

Hope that helps.

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.