Hi John, Thanks for looking into it, but I've gone with another direction now - essentially getting the sum back as a JSON parameter from the server, saving me having to derive it.
Basically put, though the table shown represents a child - the id is repeated in every row within the table. I needed to firstly check I had the right table for this child by finding the input name="child_id" that match the one passed to the function. Then I needed to find all the prices and paid_qty's per row within this table, multiply them, and sum them. It was the traversing I was having the problem with. Hopefully that makes sense - if you can see a solution, that may well end up becoming useful, if not, I always have the value passed from the server. Many thanks, Dan. On 8/7/07, John Resig <[EMAIL PROTECTED]> wrote: > > > Dan - > > Do you have a full page where this is running? Unfortunately not all > of the HTML for this document is present, so I'm not sure if there's > another issue at play here. If you could put the full HTML or a demo > online, that'd be most helpful. > > --John > > On 8/7/07, Dan Eastwell <[EMAIL PROTECTED]> wrote: > > The structuring issue aside, and as I understand it (and without > validation > > errors) in XHTML1.0 strict you can have any block level element in a > list > > element. (This may well be changing in later HTML versions, AFAIK). > > > > That aside, do you have an answer for my DOM traversing issue using > jquery? > > It's a fairly simple task, I'd imagine, for you chaps, but I'm banging > my > > head against a wall trying to work it out! > > > > Many thanks, Dan. > > > > > > On 8/7/07, Karl Rudd <[EMAIL PROTECTED]> wrote: > > > > > > Actually you can have anything inside an LI, I've used that structure > > > many times. LIs are a kind of limited block level element, limited in > > > the sense that their parent has to be an OL or a UL. > > > > > > DTs are inline elements, perhaps that's what you were thinking? > > > > > > Karl Rudd > > > > > > On 8/7/07, John Resig <[EMAIL PROTECTED]> wrote: > > > > > > > > You can't have a table and h4 inside of an LI - they're both > > > > block-level elements, so browsers automatically push them outside of > > > > the LI (meaning that you can't find them. You'll have to use some > > > > other markup structure in order to handle that. > > > > > > > > --John > > > > > > > > On 8/6/07, Dan Eastwell < [EMAIL PROTECTED]> wrote: > > > > > > > > > > > > > > > ---------- Forwarded message ---------- > > > > > From: Dan Eastwell <[EMAIL PROTECTED]> > > > > > Date: Aug 3, 2007 4:40 PM > > > > > Subject: DOM traversing problem. > > > > > To: jQuery Discussion <[EMAIL PROTECTED]> > > > > > > > > > > Given this html within a form: > > > > > > > > > > <li> <!-- Children --> > > > > > <h4><a > > > > > > > href="#Summary002">Emily</a><span>£12.50</span></h4> > > > > > <table > > id="Summary002" summary=""> > > > > > <tr > > class="accessibility"> > > > > > <th > > scope="col">Title</th> > > > > > <th > > scope="col">Quantity</th> > > > > > <th > > scope="col">Free Quantity</th> > > > > > <th > > scope="col">Cost</th> > > > > > <th > > scope="col">Remove</th> > > > > > </tr> > > > > > <tr> > > > > > <td>Book and > > the order of...</td> > > > > > <td> > > > > > <input > > type="text" class="text" > > > > > id="Item004_qty" name="paid_qty" value="3" size="3" /> > > > > > <input > > type='hidden' > > > > > name='order_detail_id' value='6213734' /> > > > > > <input > > type='hidden' > > > > > name='child_id' value='423761' /> > > > > > </td> > > > > > <td> > > > > > <input > > type="text" class="text" > > > > > id="Item004_free_qty" name="free_qty" value="4" size="3" /> > > > > > </td> > > > > > <td > > class="currency">£<span > > > > > class="price">3.50</span></td> > > > > > <td><input > > type="image" > > > > > id="Item004_remove" src="images/buttons/remove.gif" /></td> > > > > > </tr> > > > > > <tr> > > > > > <td>Book and > > the order of...</td> > > > > > <td> > > > > > <input > > type="text" class="text" > > > > > id="Item005_qty" name="paid_qty" value="2" size="3" /> > > > > > <input > > type='hidden' > > > > > name='order_detail_id' value='6213735' /> > > > > > <input > > type='hidden' > > > > > name='child_id' value='423761' /> > > > > > </td> > > > > > <td> > > > > > <input > > type="text" class="text" > > > > > id="Item005_free_qty" name="free_qty" value="5" size="3" /> > > > > > </td> > > > > > <td > > class="currency">£<span > > > > > class="price">3.50</span></td> > > > > > <td><input > > type="image" > > > > > id="Item005_remove" src="images/buttons/remove.gif" /></td> > > > > > </tr> > > > > > <tr> > > > > > <td>Book and > > the order of...</td> > > > > > <td> > > > > > <input > > type="text" class="text" > > > > > id="Item006_qty" name="paid_qty" value="1" size="3" /> > > > > > <input > > type='hidden' > > > > > name='order_detail_id' value='6213736' /> > > > > > <input > > type='hidden' > > > > > name='child_id' value='423761' /> > > > > > </td> > > > > > <td> > > > > > <input > > type="text" class="text" > > > > > id="Item006_free_qty" name="free_qty" value="3" size="3" /> > > > > > </td> > > > > > <td > > class="currency">£<span > > > > > class="price">3.50</span></td> > > > > > <td><input > > type="image" > > > > > id="Item006_remove" src="images/buttons/remove.gif" /></td> > > > > > </tr> > > > > > </table> > > > > > </li> > > > > > > > > > > I've found the child from the child_id > > > > > > > > > > function getCurrentTotal(child_id){ > > > > > var sum = 0; > > > > > > > > > > if(child_id){ > > > > > > > > > > $("ul.orders-sumary li li [EMAIL PROTECTED]").each( > > function(){ > > > > > // child in the form > > > > > > > > > > if(this.value == child_id){ // this is the child we're > > looking > > > > > for - this works > > > > > > > > > > > > $(this).parents("li").children("tr").each( > > > > > function(){ // row in the child's order > > > > > var paid_qty = $(this).children("td > > > > > [EMAIL PROTECTED]").val(); // get the value in > > the input with > > > > > name="paid" > > > > > var price = $(this).children("td > > span.price").text(); // > > > > > get the text in the span class="price" > > > > > sum += paid_qty * price; // multiply them > > together and > > > > > add them to the total > > > > > console.log("sum: " + sum); > > > > > }); > > > > > return false; > > > > > } > > > > > }); > > > > > } > > > > > return sum; > > > > > } > > > > > > > > > > The thing I'm trying to do is to get a total for all the price * > > paid_qty > > > > > from the data in the form. > > > > > > > > > > I can't seem to get these values from the form, for the child I've > > found. > > > > > > > > > > Any help appreciated. > > > > > > > > > > Cheers, > > > > > > > > > > Dan. > > > > > > > > > > > > > > > > > > > > -- > > > > > Daniel Eastwell > > > > > > > > > > Portfolio and articles: > > > > > http://www.thoughtballoon.co.uk > > > > > > > > > > Blog: > > > > > http://www.thoughtballoon.co.uk/blog > > > > > > > > > > -- > > > > > Daniel Eastwell > > > > > > > > > > Portfolio and articles: > > > > > http://www.thoughtballoon.co.uk > > > > > > > > > > Blog: > > > > > http://www.thoughtballoon.co.uk/blog > > > > > > > > > > > > > > > -- > > > > Daniel Eastwell > > > > Portfolio and articles: > > http://www.thoughtballoon.co.uk > > > > Blog: > > http://www.thoughtballoon.co.uk/blog > -- Daniel Eastwell Portfolio and articles: http://www.thoughtballoon.co.uk Blog: http://www.thoughtballoon.co.uk/blog