Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/88894-php-and-javascript/
Share on other sites

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;

 

 

Link to comment
https://forums.phpfreaks.com/topic/88894-php-and-javascript/#findComment-455334
Share on other sites

<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

Link to comment
https://forums.phpfreaks.com/topic/88894-php-and-javascript/#findComment-455386
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/88894-php-and-javascript/#findComment-455389
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.