PHP Javascript alert box


I am trying to create a basic alert box using java script and php. In my external js file i have a function like so:

<!-- hide script from old browsers function warning() { alert("Testing box!"); }
// end hiding script from old browsers -->

I then import this file into the php file by using:

<script src="function.js" type="text/javascript"> </script>

Then i have an if statement which i would like to produce this function if the statement is true. i.e:

if(code here) {

		[php]echo '<script type="text/javascript">warning();</script>'; [/php]


This is unable to call the function from the external js file.The if statement definitely executes as i have tested this. I have no idea why this isn’t working, any idea?

There’s nothing wrong with the php, its how you’re trying to use the function. You need to use it with an event selector, like onChange, onClick, etc.

Sponsor our Newsletter | Privacy Policy | Terms of Service