Jump to content

Nesting javascript in PHP If ?


toasty525

Recommended Posts

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.  :confused:

Link to comment
https://forums.phpfreaks.com/topic/189739-nesting-javascript-in-php-if/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.