Hey all,

I have a simple if() statement (see below) that I need to generate a JavaScript alert when the result of the elseif() inside the statement is true.

 //Check to see if the system ID exists
		if(isset($id)){
		$id_query = mysql_query("SELECT id FROM nuke_trakker_system WHERE id = '".$id."'");

	if(mysql_num_rows($id_query) == 0){
		echo "We're sorry but the system ID you have entered is invalid. Please check the ID and try again.";
		}
	elseif(mysql_num_rows($id_query) == 1){
			echo "<script language=JavaScript>";
			echo "window.alert('Pleaes note that your machine is NOT ready for pickup until Status reads: Service Completed!\n\nThank You for your business!');";
			echo "</script>";
		}
	}

Right now the pages works and no errors are given, all the pertinent information is displayed but the JavaScript alert is not processed. Any ideas? I'm not trying to redirect or anything. Simply alert the user to the notice in the window.alert(); before they see their information.

Thanks!

    take out the "window." part, just use alert

      Hmm... still didn't work. Same result as before. Any other ideas? I appreciate the quick response! Thanks.

        I would do it this way

        <?php
        //Check to see if the system ID exists
        if(isset($id)){
        	$id_query = mysql_query("SELECT id FROM nuke_trakker_system WHERE id = '".$id."'");
        
        if(mysql_num_rows($id_query) == 0){
        	echo "We're sorry but the system ID you have entered is invalid. Please check the ID and try again.";
        }
        elseif(mysql_num_rows($id_query) == 1){
        	$alert= <<<_ALERT_
                    "onload="alertNotification()"";
        _ALERT_;
        }
        } else{
        ?>
        
        <html>
        <head>
        <title>An onload script</title>
        <script type=text/javascript>
        <!--
        function alertNotification() {
        alert("Please note that your machine is NOT ready for pickup until Status reads: Service Completed!\n\nThank You for your business!");
        }
        // -->
        </script>
        </head>
        <body <?php if(isset($alert)) {print $alert;} ?>>
        Here is some body text.
        </body>
        </html>
        
        
        <?php
        }
        ?>

        You need an event to trigger the alert.

          By doing it that way won't it redirect the user to another page that they would then have to navigate back from? Thereby forcing them into a loop?

            No, that is just an example of how to do it. You can pass the $alert variable from your processing page to another page with a $_SESSION var.

            All I have done is to show how to echo the line on the body event in order to trigger the alert, if the elseif condition occurs. If it doesn't occur then the onload line won't be written in the html page and therefore won't trigger.

            You would simply need to add the javascript function into your existing page, and then change the <body> tag as shown.

              Thanks for all the help guys. I figured it out by playing around with it some more. Apparently where I had the \n\n wasn't parsing. I had to escape it properly so PHP would parse it. Simple re-write of \n\n gave me exactly what I needed!

                Write a Reply...