javascript if clause & php<

admin

Administrator
Staff member
It seems javascript if statement doesn't work with php.
Following code prints "hibye" for either OK or Cancel.

<?php
?>
<script language='javascript'>
if (confirm("Okay or Cancel."))
{
<?php
$x = "hi";
?>
}
else
{
<?php
$y="bye";
?>
}
</script>

<?php
print $x;
print $y;
?>

I want to do some mysql query inside the if statement after user confirms with the confirm window.. Any solution?you cant not combine php with javascript! php is parsed and evaluated BEFORE the javascript is even thought about by the browser. you have to make it all php.That's a sad news.
Well, got to find another way around then.

Thanks.if you wanted to do that script, you could do it all as javascript. then submit it as a form to a php script, or via the query string. javascript is a clientside language, while php is a serverside language, they cant interact dynamically in that way.
 
Back
Top