Forum Moderators: coopster
I want the user to be able to update the quantity of each item using this:
<input type="text" size="10" name="qty" value="<?php echo $row['qty'];?>" /> <a href="cart.php?action=update_item&id=<?php echo $row["itemId"];?>&qty=?">Update</a> When the user clicks on Update I want the value of the text input field to be inserted into the "&qty=?" of the Update link. I thought there might be some javascript that I could use to achieve this but I have yet to find it. Thanks again!
-Radium
In <head>:<script language="javascript" type="text/javascript">
function updateLink() {
var qty = document.update.qty.value; //Get the form field 'qty' in form 'update'
var url = 'cart.php?action=update_item&id=&qty='; //Set the url it is to be added to
var total = url + qty; //Combine into the final URL
location.href = total; //Redirect User
}
</script>Link Code:
<form name="update"><input type="text" size="10" name="qty" value="<?php echo $row['qty'];?>" /></form><a href="javascript:updateLink();">Update</a>
You may need to change some tags to make them XHTML copliant, but I use HTML 4.01 so I don't know what to change!
Hope this helps
Chris
I tried this but I don't know how to get the variable itemId to insert after qty_
document.frmCart.qty_.value; In Head:
<script type="text/javascript">
function updateLink(itemId) {
var qty = document.frmCart.qty_itemId.value; // Get the form field 'qty' in form 'update'
var url = 'cart.php?action=update_item&id='+ itemId +'&qty='; // Set the url it is to be added to
var total = url + qty; // Combine into the final URL
location.href = total; // Redirect User
}
</script> In Body:
<input type="text" size="10" name="qty_<?php echo $row["itemId"];?>" value="<?php echo $row['qty'];?>" /> <a href="javascript:updateLink('<?php echo $row["itemId"];?>');">Update</a>
<script type="text/javascript">
function updateLink(itemId) {
var qty = document.frmCart.qty_<?php echo $row["itemId"];?>.value;
var url = 'cart.php?action=update_item&id='+ itemId +'&qty=';
var total = url + qty;
location.href = total;
}
</script>
Chris
<form name="update_item" method="get">
<input type="hidden" name="action" value="update_item" />
<input type="hidden" name="id" value="<?php echo $row['itemId'];?>" />
<input type="text" size="6" name="qty" value="<?php echo $row['qty'];?>" /> <input type="submit" value="Update" /></a>
</form> The URL winds up like this:
cart.php?action=update_item&id=1&qty=200 Works perfectly! :)