Jquery .each() Function Accessing Other Selector Via Indexes
I have some code like so: var theQuantities = $('#' + theWindowID + '_form INPUT[name=f\\[invoices_items\\]\\[quantity\\]\\[\\]]'); var theValues = $('#' + theWindowID + '_form INP
Solution 1:
When calling a jquery array object using brackets (like theQuantities[i]
) you're getting back an HTML node element, not a jQuery object.
try using theQuantities.eq(i)
which will return the jQuery object in position i, then you can use jQuery's val()
for more on eq, see jQuery documentation: https://api.jquery.com/eq/
Given a jQuery object that represents a set of DOM elements, the .eq() method constructs a new jQuery object from one element within that set. The supplied index identifies the position of this element in the set.
Solution 2:
You can try this
var theSubTotal = parseFloat(($(theQuantities[i]).val() * $(theValues[i]).val()) - $(theDiscounts[i]).val()).toFixed(2);
Post a Comment for "Jquery .each() Function Accessing Other Selector Via Indexes"