...

View Full Version : echo Auto Execute



lipak
06-07-2005, 02:38 AM
Hello,

Im not sure which this will end up being a PHP or a JavaScript question.

I have a form that, after submitting it, a link appears in the echo with an onClick that when clicked opens a window. I am wondering how to make this action (the onClick) automatic so that when the form is submitted the echo automatically opens the window.

I have attached a simple example of my current form.

Thank you for any help in advance.

Kid Charming
06-07-2005, 02:53 AM
I'd probably run my body tag through an if statement: If your form's been submitted, have it put an onLoad in the tag.

lipak
06-07-2005, 03:05 AM
Thanks for the response.

I'm not sure how to implement that. Your assistance would be greatly appreciated.

Kid Charming
06-07-2005, 03:28 AM
if( $_POST['yoursubmit'] )
{
echo '<body onLoad="yourFunction()">';
}
else
{
echo '<body>';
}


I may have the onLoad syntax off; you may want to double-check it.

[Edit] I'm pretty sure the onLoad won't go into affect until after the entire page has been served up, so it shouldn't interfere with any processing. I've never tried it, though, so you may want to run a couple of tests... ;)

lipak
06-07-2005, 07:47 AM
I spent awhile attempting to implement your suggestion. Unfortunately I have not yet been successful. I do have a couple questions. In the end, will the body tag in the echo interfere with the body tag at the top of the html? Second, what value should I be putting where 'yoursubmit' is?

Thanks again.

Serex
06-07-2005, 09:47 AM
if( $_POST['yoursubmit'] )
yoursubmit would be changed to the name of your submit button. By default the name of it should be Submit so you would use.


if( $_POST['Submit'] )

just be carefull of case sensitive names and make sure they match. also the <body> tags that are echo'd should not be rendered to the browser as long as you have it placed in the right spot you should be fine.

i.e



<html>
<head>
<script>
function test()
{
alert('lah lah lah');
}
</script>
</head>
<?
if( !isset($testing) )
{
echo '<body onLoad="test()">';
}
else
{
echo '<body>';
}
?>
Body of your page here
</body>
</html>

lipak
06-07-2005, 07:37 PM
Thank you very much Kid Charming and Serex!

It works beautifully. I found (as Serex said) that the PHP code needs to be placed above the body tag of the html. Then when the form is submitted the body tag in the echo sort of "overrides" the existing body tag.

Thanks again! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum