---------- 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>&pound;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">&pound;<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">&pound;<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">&pound;<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

Reply via email to