0

I have several div's with the class .agrRow. In each .agrRow there is an input field with the name agrPrice.

I want to get the value of that field for each instance of .agrRow. I've tried something like:

    $(".agrRow").each(function(){           

            // get price for this field
            lp=parseFloat( $("input[type='text'][name='agrPrice']").val() );
    });

but that only ever gives me the value of agrPrice in the first instance of .agrRow class.

I'm sure I need to incorporate "this" but I'm not sure how.

What is the correct syntax?

1
  • And what do you intend to do with all the values ? Commented Oct 28, 2014 at 16:37

2 Answers 2

2

You should find the input element in current teration context. you can use:

 $(".agrRow").each(function(){           
    // get price for this field
    lp=parseFloat($(this).find('[name=agrPrice]').val());
 });

To get them all in array:

  $(".agrRow [name=agrPrice]").map(function(){
    return parseFloat($(this).find('[name=agrPrice]').val());
  }).get()
Sign up to request clarification or add additional context in comments.

2 Comments

From OP: there is an input field with the name agrPrice. not class .agrPrice
@AmitJoki: exactly. why make things complicated :). thnx for edit.
0

You should use the this context to get the input inside the iterating div.

$(".agrRow").each(function(){           
   // get price for this field
   lp=parseFloat($(this).find("input[type='text'][name='agrPrice']").val() );
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.