Click to See Complete Forum and Search --> : How/When do I call this function?


tgrk35
12-11-2007, 08:09 PM
Um, so I am submitting a form...and processing it with php...

So, within the php conditional, I would like to call a javascript function...

Can I just do like this or is there a better way?:


if(isset($_POST['submit'])){

echo '<script type="text/javascript">';
echo 'ripcord();';
echo '</script>';

}


Thanks for all your help :)
Will

AmazingAnt
12-12-2007, 03:29 PM
About the only "easier" way to do that, would be to throw it all on one line like so

if(isset($_POST['submit'])){echo '<script type="text/javascript">ripcord()</script>'}

Sheldon
12-12-2007, 08:14 PM
if all you are doing with the PHP is setting a javascript function, why use PHP at all?



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Submit Test</title>
<script type="text/javascript" charset="utf-8">
function testJavaScript(){
alert("Form is submitted.");
}
</script>
</head>

<body>

<form action="" method="get" accept-charset="utf-8">
<p><input type="submit" value="Continue &rarr;" onclick="testJavaScript();"></p>
</form>

</body>
</html>