Using javascript variable in php inside javascript function

In my code a javascript function received value from html hyperlink. Value passing successfully, inside product function document.write(a) printing value 5.
But how can i print value of “a” inside product function by php. My code is here…

[I]<html>
<body>

<a href=‘javascript: product(5);’>click</a>

<script type=‘text/javascript’>

function product(a)
{
document.write(a)

document.write("<?php

echo “some thing”;

?>");

}
</script>
</body>
</html>[/I]

PHP is a server side language, JavaScript is a client side language. They are doing completely different parts of serving your page, you can’t mix them.

Process works like this:

  1. Server generates page. <– PHP
  2. Server sends page to client. <– As soon as last byte of page is sent, server stops being involved in page generation. PHP can’t be used after that.
  3. Browser receives page. <!-- Start of JavaScript involvement

PHP and JavaScript are doing completely different things on different sides of serving the page. They can’t interact.

Brother CyberAlien, inside php code javacript code can ran,

<? php
$mi=“<script type=‘text/javascript’>document.write(5234);</script>”;
echo $mi; // print 5234
?>
My problem is, inside javascript function passing javascript variable to php variable.

No, it doesn’t run. You are just echoing text. Browser then treats text as script and runs it when you’ve sent whole page.

in my main code i can not run javascript code inside php code…

<html>
<body>

<a href=‘javascript: product(5);’>click</a>

<script type=‘text/javascript’>

function product(a)
{
document.write(a)

document.write("<?php

$mi=“<script type=‘text/javascript’>document.write(a);</script>”;
echo $mi;

?>");

}
</script>
</body>
</html>

this is my problem, $mi not printing anything

Look at the rendered source code of the page and you will find that some fundamental HTML errors are getting in your way.