Onchange弹出错误javascript

I try to auto calculate the input without any button. I try to do it with javascript onchange function.However, javascript keep pop out the error and I do not know how to solve it.

This is the error : Uncaught SyntaxError: Unexpected identifier

below is my code :

<!DOCTYPE html>
<html>

<script>
function jsfunction()
{
var x=document.getElementById("qty1");
var y =document.getElementById("price1");
var z =document.getElementById("total1");


   alert("You entered: " + y.value);


}
</script>

<body>
<?php
$item=array("A"=>"10","B"=>"11","C"=>"12","D"=>"13");
$var=1;
$total=0;
$gtotal=0;

?>
<table border=1 width='600'
<tr>
<th>No</th>
<th>item</th>
<th>Check</th>
<th>Price</th>
<th>Qty</th>
<th>Total</th>
</tr>";
<?php
foreach($item as $myItem=>$pricetag){
echo "<tr>";
echo "<td>".$var."</td>";
echo "<td>".$myItem."</td>";
$price = "price". $var;
$qty = "qty". $var;
$total = "total". $var;
?>

<td><input type="checkbox" id="chkbox" name="chkbox"/></td>
<td><input type="text" name=<?php $price ?> id=<?php $price ?>  size =1/><?php  echo $price ?> </td>
<td><input type="text" onchange="jsfunction() name=<?php $qty ?> id=<?php $qty ?> size =1/><?php echo $qty ?></td>
<td><input type="text" name=<?php $total ?> id=<?php $total ?> size =1/></td>


<?php
$var++;
}?>


</table>
</form>
</body>
</html>

Well, there are a few problems:

  1. You never have the closing > of the <table> tag:

    <table border=1 width='600' => <table border=1 width='600'>

  2. You have a random "; when the code is not even PHP nor JavaScript:

    <th>Total</th>
    </tr>";
    
  3. You are using the PHP tag as an echo tag:

    <?php $price ?> => <?php echo $price ?>

  4. You never close the double quotes when calling your JavaScript function:

    onchange="jsfunction() => onchange="jsfunction()"

  5. EDIT:
    If your name property is NULL, it may cause problems because the id will be set to the name, so you should wrap the name in quotes (Just to be safe you should probably do it with everything including id, size, name, etc.):

    name=<?php $price ?> => name="<?php $price ?>"

Among other things, this line has a JavaScript error:

<td><input type="text" onchange="jsfunction() name=<?php $qty ?> id=<?php $qty ?> size =1/><?php echo $qty ?></td>

It should probably be:

<td><input type="text" onchange="jsfunction()" name="<?php echo $qty; ?>" id="<?php echo $qty; ?>" size="1" /><?php echo $qty; ?></td>

You must use the echo function to print out a PHP variable to the HTML.

Also, throughout your HTML form, don't forget to wrap all the input parameter values in quotation marks (" ").

What is the value of $price? You are getting element's by their id, e.g. price1, but if $price is not equal to the string 'price1' it will fail to get an element by that id and your javascript will be calling into a null value.