Set value of input element using javascript and get the value using php -


here have form , input element:

cart.php

<form id="cartform" action="cart.php?action=update&pd=<?php echo $row['product_id'] ?>" name="form1" method="post"> <?php     $query = "select * cart customer_id='$user' ";     $result = mysqli_query($con,$query);$payableamount = 0;$totalsavings = 0;     while($row = mysqli_fetch_array($result))     {         $productid = $row['product_id'];         $query2 = "select * product product_id='$productid'";         $result2 = mysqli_query($con,$query2);         while($row2=mysqli_fetch_array($result2))         { ?>             <input tpe="text"  name="quantxt[]" id="quantxt" value="<?php echo $qty = $row['quantity']; ?>" onkeyup="showsubmit(<?php echo $row['cart_id'] ?>,<?php echo $row['product_id'] ?>)">             <input type="text" name="s1" id="s1" value=""/>             <input style="visibility:hidden;width:80px;border-radius:10px;background-color:green;border:none;padding:5px;color:white;"                type="submit"                name="sub_<?php echo $row['cart_id'] ?>"                id="sub_<?php echo $row['cart_id'] ?>"                value="update"> </table>     </form> 

and javascript is:

<script>     function showsubmit(id,prodid)     {         alert(id);         alert(prodid);         document.getelementbyid("sub_"+id).style.visibility ="visible";         document.getelementbyid("s1").value = prodid;         f = document.getelementbyid("s1").value;         alert("product id is:"+f);     } </script>  

when accessign value of s1 element in cart2.php gives nothing. on next page s1 has no value,while expecting value updated using javascript

$prod_id = $_post['s1']; echo "product id of clickable product is:".$prod_id."<br>"; 

this line:

<input type="text" name="s1" id="s1" value=""/> 

is inside loop. can make sure loop has 1 row returning? because if not, you're creating multiple elements same id javascript can not catch properly. id supposed unique. in case of multiple same ids it'll catch first match , stop.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -