Hi I have run into a small problem, I am trying to run a java script in my php page, but only when a certain php values is set. The java script must only run in this case and at the moment I can only seem to get it to run in every case. The code looks something like this: <? if ($message==1) echo $lang[acc_succ_act]; (this is the only case I want to run the jave script) else if ($message==2) echo $lang[acc_already_act]; else echo $lang[act_err];?> Please can someone help me! Thanks
it'll be something like this: if ($message==1) ) { echo $lang[acc_succ_act]; (this is the only case I want to run the jave script) } elseif ($message==2) ){ echo $lang[acc_already_act]; } else { echo $lang[act_err]; } Code (markup):
I never knew you could run JavaScript in PHP! I've always been told you couldn't! Thanks for the code!
Ok I got it working This is how i did it <? if ($message==1) { ?> <script type='text/javascript'></script> <? } else { ?> blaa <? } ?>
php doesnt run the javascript... it just outputs what javascript you want to show up on the page... you still need the javascript to make the call to run whatever you are trying to do
i hope it works: if ($message==1) ) { echo $lang[acc_succ_act]; //your JS echo "<script language='javascript'>"; echo "<!-- "; echo "alert('your Javasript')"; echo "//-->"; } elseif ($message==2) ){ echo $lang[acc_already_act]; } else { echo $lang[act_err]; } Note: donot use " inside echo use only '
You cant run the javascript within the php code. what you can do is to write the javascript and php will print it out then it will function properly
or use includes for eg.. if (condition=comparison) { include(myjs1.htm); // js1.htm contains ONLY the javascript and the script goes on....