John Davidson

javascript - table rows are printing in a php loop and i want to enter in table row cell from java script, if i print in console it giving correct output

0 comments
Message:


`while ($row=mysqli_fetch_assoc($result) ) {`
`$food=$row["order_name"];`
`$price=$row["order_price"];`
`$quantity=$row["order_quantity"];`
`echo '<form action="/wowfood/cart.php" method="post">`
`<tr>`
`<th scope="row">'.$sno.'</th>`
`<td>'.$food.'<input type="hidden" name="order_name" value="'.$food.'"</td>`
`<td> <input type="number" class="iquantity" onchange="subtotal()" value="'.$quantity.'" min=1 style="hight: 25px;width: 45px;display: block;border: 1px solid black;border-radius: 6px;"> </td>`
`<td>'.$price.'<input type="hidden" class="iprice" value="'.$price.'"</td>`
`<td id="itotal"></td>`
`<td><button type="submit" class="btn btn-danger btn-sm">Remove</button></td>`
`</tr>`
` </form>';`
`$sno=$sno+1;`
'}'


`<script type="text/javascript">`
`var iprice= document.getElementsByClassName("iprice");`
`var iquantity=document.getElementsByClassName("iquantity");`
`var itotal=document.getElementById("itotal");`
`function subtotal(){`
`for (i = 0; i<iprice.length; i++) {`
`itotal[i]= (iprice[i].value)*(iquantity[i].value);`
`console.log(itotal[i]);`
` }`
` }`
`subtotal();`

`</script>`



i am trying to print the value of th tag with id itotal itotal depends on iqauntity and iprice if i console print the value it is giving the correct values but i am failed to put that value in html.
i total eitehr giving an html list or on console it giving correct values.
basically i have a table in which i wan to change the subtotal on the basis of quantity.
thanks in advance



My Answer:
"food"];`_

`echo "";`
`echo "".$food."";`
`echo "";`
`echo "";`
`}`

In this code snippet, you are fetching data from a MySQL database using PHP and printing it in a table row. You want to enter a table row cell from JavaScript.

In the code snippet provided, you are using PHP to print the table rows and cells. If you want to include JavaScript code within the table cell, you can use the `";
echo "";
echo "";
}


In this example, the JavaScript code within the table cell will dynamically generate the content based on the value of the `$food` variable fetched from the database.

Rate this post

4 of 5 based on 3241 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us