toasty525 Posted January 25, 2010 Share Posted January 25, 2010 Hi, is it posible to nest simple java script in a PHP IF statment for example i have the following code: if ($row == 0) { ?> <SCRIPT language="JavaScript"> alert('Sorry not this time, Please try again !'); </SCRIPT> <? } else { echo $row['prize']; } When $row = 0 its meant to show an alert box but it dosnt work. Link to comment https://forums.phpfreaks.com/topic/189739-nesting-javascript-in-php-if/ Share on other sites More sharing options...
RussellReal Posted January 25, 2010 Share Posted January 25, 2010 You can't have javascript run while php is still running, essentially what this script will do is output that when the php engine exits.. so you will get the alert AFTER php exits.. Link to comment https://forums.phpfreaks.com/topic/189739-nesting-javascript-in-php-if/#findComment-1001329 Share on other sites More sharing options...
calmchess Posted January 25, 2010 Share Posted January 25, 2010 you can do it <?php if(1==1){ ?> <!-- java script here--> <?php }else{ } ?> Link to comment https://forums.phpfreaks.com/topic/189739-nesting-javascript-in-php-if/#findComment-1001333 Share on other sites More sharing options...
Adam Posted January 25, 2010 Share Posted January 25, 2010 you can do it <?php if(1==1){ ?> <!-- java script here--> <?php }else{ } ?> That's basically what he had, except with "$row == 0". Most likely if you're not seeing the JS output you're expecting, there's something wrong with the condition. Could you post more code? At a guess I'd say you're using the mysql_* functions incorrectly. Link to comment https://forums.phpfreaks.com/topic/189739-nesting-javascript-in-php-if/#findComment-1001339 Share on other sites More sharing options...
RussellReal Posted January 25, 2010 Share Posted January 25, 2010 you might also want to do type="text/javascript" Link to comment https://forums.phpfreaks.com/topic/189739-nesting-javascript-in-php-if/#findComment-1001357 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.