homepage Welcome to WebmasterWorld Guest from 54.163.84.199
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Traversing table rows method - why one works when other does not.
nelsonm




msg:4459588
 7:23 pm on May 30, 2012 (gmt 0)

Hi all,

while i do have a solution for traversing table rows in order to calculate unitprice, quantity and cost...

I was wondering why my first attempt does not work while the other does.


this does not work using: $(this+' input[name="a field"]')
function recalcTotals(){
var subtotal = 0.00;

// get each item line cost and calculate subtotal.
$('#workorder-form #sa-table-1 tbody tr').each(function (){

if($(this+' input[name="wi-Cost"]').val() != ''){

$(this+' input[name="wi-Cost"]').val(parseFloat($(this+' input[name="wi-UnitPrice"]').val()) * parseFloat($(this+' input[name="wi-QTY"]').val()));

subtotal += parseFloat($(this+' input[name="wi-Cost"]').val());
}
});


this does work using: $(this).find('input[name="a field"]')
function recalcTotals(){
var subtotal = 0.00;

// get each item line cost and calculate subtotal.
$('#workorder-form #sa-table-1 tbody tr').each(function (){

if($(this).find('input[name="wi-Cost"]').val() != ''){

$(this).find('input[name="wi-Cost"]').val(parseFloat($(this).find('input[name="wi-UnitPrice"]').val()) * parseFloat($(this).find('input[name="wi-QTY"]').val()));

subtotal += parseFloat($(this).find('input[name="wi-Cost"]').val());
}
});


It seems to me that both selector methods reference the same element.

thanks.

 

Fotiman




msg:4459616
 8:55 pm on May 30, 2012 (gmt 0)

The jQuery function ($) takes a string selector or an object as it's parameter.

$(this+' input[name="a field"]')

That will coax this object to a string by implicitly calling it's toString() method, which might give you something like:
[Object object]
rather than the element you were hoping for.

nelsonm




msg:4459620
 9:23 pm on May 30, 2012 (gmt 0)

[Object object] is exactly what i got.

I'll leave it alone since the method that works appears to be the proper method in this case.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved