How to pass PHP variable through PHP

Hi!!
I am trying to find out solution for this since long.
I tried js but as I am not good with it, I just want to do this through PHP.

I am adding dynamic rows when user clicks the Add Row button.I want to show the calculated amount like:
line_total=qty*unit_price;

if (isset($_POST['qty']) && sizeof($_POST['qty']) > 0)  {
    for($i = 0, $maxi = count($_POST['qty']); $i < $maxi; $i++)  {
        $quantity    = (isset($_POST['qty'][$i]) && !empty($_POST['qty'][$i])) ? mysql_real_escape_string($_POST['qty'][$i]) : 0;
        $description = (isset($_POST['description'][$i]) && !empty($_POST['description'][$i])) ? mysql_real_escape_string($_POST['description'][$i]) : 0;
        $unit_price  = (isset($_POST['unit_price'][$i]) && !empty($_POST['unit_price'][$i])) ? mysql_real_escape_string($_POST['unit_price'][$i]) : 0;
        $line_total  = (isset($_POST['line_total'][$i]) && !empty($_POST['line_total'][$i])) ? mysql_real_escape_string($_POST['line_total'][$i]) : 0;
		?>
		<?php   $myvar=$quantity*$unit_price;   ?>

	<script type="text/javascript">
		jsvar = <?php echo $myvar; ?>;
		document.write(jsvar);  // Test to see if its prints array:
                	</script>
	}		
} 

This code works very well and displays the values.But if I use it in the function like;

function line(elem) {
jsvar = <?php echo $myvar; ?>;

document.getElementById("line_total").value = jsvar;
		}
And call it:

<input type="text" name="line_total[]" id="line_total" onBlur="return line(this)">

It is not showing the result. Kindly guide me where I am going wrong :frowning:

Shouldn’t you put the variable into brackets like this:

 
function line(elem) { 
var jsvar = "<?php echo $myvar; ?>";
 document.getElementById("line_total").value = jsvar;        
 } 

If it doens’t work, try adding slashes to the special chars:

var jsvar = “\<\?php echo \$myvar; \?\>”;

I tried this bulevardi.But its still not responding to onblur event :frowning:

Perhaps you should try to call your javascript like this way:

<input type=“text” name=“line_total” id=“line_total” onBlur=“line(this)”>

Finally I got solution for this problem after a long search over internet and forum :slight_smile:
And I am thankful to all you guys for ur constant support.