SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question jQuery Help with selectors please.

    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 &pound;<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 &pound;</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.

  2. #2
    SitePoint Zealot Gar onn's Avatar
    Join Date
    Feb 2011
    Location
    Belgium
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try:
    Code:
    $(this).parent().find('span.unit_price').text();

  3. #3
    SitePoint Member
    Join Date
    May 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahaaa, that works nicely. Thank you friend.

    My actual name is Tom btw, I'm new here to these forums. There may be many other silly questions from me to follow shortly.....but hopefully not.

  4. #4
    SitePoint Member
    Join Date
    May 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, equally, what would I have to do in order to select the corresponding productTotal?

    Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •