abyssal Posted February 22, 2012 Share Posted February 22, 2012 Does JavScript run ONLY if included in a php if/else statement ? Here is a quick example: 1 is not higher than 2, so the else statement will run. My question is, will the first javascript1 code run too, or it will follow the if/else statement in php ? if (1>2) { <javascript code1> } else { <javascript code2> } Quote Link to comment https://forums.phpfreaks.com/topic/257526-quick-javascript-in-php-ifelse/ Share on other sites More sharing options...
spiderwell Posted February 22, 2012 Share Posted February 22, 2012 the php if statement should work just like any other time you use one, just in this instance you are telling php to output javascript, there is no reason why it would run both. Quote Link to comment https://forums.phpfreaks.com/topic/257526-quick-javascript-in-php-ifelse/#findComment-1319949 Share on other sites More sharing options...
abyssal Posted February 22, 2012 Author Share Posted February 22, 2012 Well the javascript code is actually some kind of redirect, so I was wondering if it works as intended. Quote Link to comment https://forums.phpfreaks.com/topic/257526-quick-javascript-in-php-ifelse/#findComment-1319951 Share on other sites More sharing options...
trq Posted February 22, 2012 Share Posted February 22, 2012 PHP simply outputs content to the browser. In your case, it would output the JavaScript contained in your else statement. Wether it *runs* or not depends entirely on your JavaScript code. Quote Link to comment https://forums.phpfreaks.com/topic/257526-quick-javascript-in-php-ifelse/#findComment-1319952 Share on other sites More sharing options...
spiderwell Posted February 22, 2012 Share Posted February 22, 2012 PHP simply outputs content to the browser. In your case, it would output the JavaScript contained in your else statement. Wether it *runs* or not depends entirely on your JavaScript code. you can redirect in php, so maybe you dont need javascript at all? Quote Link to comment https://forums.phpfreaks.com/topic/257526-quick-javascript-in-php-ifelse/#findComment-1319959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.