View Full Version : populate hidden field values from select
When I change the qty and price hidden fields to be text fields, I can see this code posting the correct info on the page, but it's not submitting... any ideas appreciated!
<form name="form_152" action="addtocart.aspx" method="post">
<input name="ItemNbr" value="12345" type="hidden"><br>
<input name="product" value="SAMPLE" type="hidden"><br>
<select onchange="this.form.price.value=this[this.selectedIndex].value;this.form.qty.value=this[this.selectedIndex].text">
<option value="5.00">1</option>
<option value="4.50">2</option>
<option value="4.00">3</option>
</select>
<input name="qty" value="" id="qty_152" type="text"><br>
<input name="price" value="" type="text">
<input name="submit" value="Add To Cart" type="submit">
</form>
I've been toying with this for a week... since I can see the correct numbers posting to the text fields onchange, the code above pulling the right values and text, but not submitting... so I tried moving it to the form onSubmit. This doesn't work:
<form name="form_152" action="addtocart.aspx" method="post" onSubmit="this.form.price.value=this[this.selectedIndex].value;this.form.qty.value=this[this.selectedIndex].text">
<input name="ItemNbr" value="12345" type="hidden">
<input name="product" value="SAMPLE" type="hidden">
<select>
<option value="5.00">1</option>
<option value="4.50">2</option>
<option value="4.00">3</option>
</select>
<input name="qty" value="" type="hidden">
<input name="price" value="" type="hidden">
<input name="submit" value="Add To Cart" type="submit">
</form>
Can anyone help please?
I'm still stuck on this - the second example must be close but I can't make it work. Any JS experts that can lend a hand? FYI, I have access to the head section but can't use any JS there that targets the specific form because this will end up on a page with 30 or more products using this code, which would make the code way too long.
Well.. this whole problem started because of a hosted cart's limitations which I'm trying to get around, and I copied their sample code and started modifying from there. Turns out their sample code doesn't work period, so scratch this.
I found a better way to achieve what I'm trying to do, because it pulls pricing from the database rather than trying to pass it with my custom code, BUT... this uses a select to choose quantity, and I would prefer to let users enter their quantity. I searched for ways to append text field input to a url but couldn't find anything that worked. Can anyone help with this?
<form name="form_152" id="form_152" action="">
<select onchange="window.open(this.options[this.selectedIndex].value,'_top')">
<option value="">Quantity</option>
<option value="AddToCart.aspx?ItemID=152&Quantity=1">1</option>
<option value="AddToCart.aspx?ItemID=152&Quantity=2">2</option>
<option value="AddToCart.aspx?ItemID=152&Quantity=3">3</option>
<option value="AddToCart.aspx?ItemID=152&Quantity=4">4</option>
</select>
</form>