alin19 Posted February 1, 2008 Share Posted February 1, 2008 can php and javascript be mixet? e meen something like this <html> <body> <script language="Javascript" type="text/javascript"> <!-- var ion ='ion' alert ('clientul este:' + ion) --> </script> </body> </html> <html> <body> <script language="Javascript" type="text/javascript"> <!-- var ion ='ion' alert ('clientul este:' + <?php echo "ion"; ?>) --> </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/88894-php-and-javascript/ Share on other sites More sharing options...
skali Posted February 1, 2008 Share Posted February 1, 2008 Yes, It can be done since PHP is a server side language and javascript is client side language. You can use conditions etc in your php code that will be reflected on the client side during js execution. Quote Link to comment https://forums.phpfreaks.com/topic/88894-php-and-javascript/#findComment-455326 Share on other sites More sharing options...
alin19 Posted February 1, 2008 Author Share Posted February 1, 2008 can i do something like this?: <html> <body> <script language="Javascript" type="text/javascript"> <!-- <?php for($i=1;$i<5;$i++) echo <<<EOF alert ('clientul este:' + EOF; echo $i; echo ")"; ?> --> </script> </body> </html> i want that the numbers in the alert window to change; Quote Link to comment https://forums.phpfreaks.com/topic/88894-php-and-javascript/#findComment-455334 Share on other sites More sharing options...
jordanwb Posted February 1, 2008 Share Posted February 1, 2008 Yes you could do that. Just make sure all the quotes are properly placed and if necessary escape them. Quote Link to comment https://forums.phpfreaks.com/topic/88894-php-and-javascript/#findComment-455363 Share on other sites More sharing options...
alin19 Posted February 1, 2008 Author Share Posted February 1, 2008 <html> <body> <script language="Javascript" type="text/javascript"> <!-- <?php for($i=1;$i<6;$i++) echo "alert ('clientul este:' + $i )"; ?> --> </script> </body> </html> it only works if $i=1,$i<2; Quote Link to comment https://forums.phpfreaks.com/topic/88894-php-and-javascript/#findComment-455374 Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 <html> <body> <script language="Javascript" type="text/javascript"> <!-- <?php for($i=1;$i<6;$i++) echo "alert ('clientul este:' + $i );\n"; ?> --> </script> </body> </html> Update: I added a semicolon and a new line character at the end of JavaScript alert(). Before, it would have printed: ... alert ('clientul este:'+ 1)alert ('clientul este:'+ 2)alert ('clientul este:'+ 3)alert ('clientul este:'+ 4) ... which is not valid JavaScript Quote Link to comment https://forums.phpfreaks.com/topic/88894-php-and-javascript/#findComment-455386 Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 you can also simplify it a little more and get rid of the +: <html> <body> <script language="Javascript" type="text/javascript"> <!-- <?php for($i=1;$i<6;$i++) echo "alert ('clientul este: $i');\n"; ?> --> </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/88894-php-and-javascript/#findComment-455389 Share on other sites More sharing options...
alin19 Posted February 1, 2008 Author Share Posted February 1, 2008 10x; it works but i was aspecting something else, instead of opening 5 windows, only one and the number to change withowth pressing ok, Quote Link to comment https://forums.phpfreaks.com/topic/88894-php-and-javascript/#findComment-455401 Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 OH...didn't catch that part before. That isn't possible with a standard alert box. You would have to do your own custom message box via an absolute positioned div. Quote Link to comment https://forums.phpfreaks.com/topic/88894-php-and-javascript/#findComment-455404 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.