Hi, I’m trying to make a product order form that updates automatically as values are entered. For each product my html is as follows:
<div class=“product”>
<img class=“product_img” src=“http://www.sitepoint.com/forums/images/very_berry.jpg” alt=“Very Berry” width=“160” height=“120”/>
<p class=“product_title”>Very Berry</p>
<p class=“product_description”>A delightfully zingy combination of blended strawberries, rasberries and blueberries. Best served simply blended with ice.</p>
<span>Unit Price £<span class=“unit_price”>22.99</span></span>
<label class=“label” for=“inputQty”>Qty : </label>
<input name=“inputAmount” type=“text” class=“inputQty” id=“qty_berry” value=“0” size=“4”/>
<label class=“label” for=“productTotal”>Product Total £</label>
<input name=“productTotal” type=“text” class=“productTotalShow” id=“productTotalBerry” value=“0” size=“8” disabled=“disabled”/>
</div>
I firstly select the ‘inputQty’ with: $(‘.inputQty’).blur(function() {
//Get the quantity value entered by the user
enteredQty = $(this).val();
But next I want to also select and strore the value from the corresponding ‘unit_price’ within the span. How do I select this with jQuery? I’m very new to this so my knowledge of how to navigate the DOM is poor. I’ve tried this:
//Find the corresponding unit price for that product
var unitPrice = $(this).find("span.unit_price").text();
Any help would be greatly appreciated.
Thanks.