0

I have multiple hidden inputs with the name image_values:

<input class="imageValues<?=$category->cat_id;?>" name="image_values[]" type="hidden" value="<?=$step->img_pos.":".$option->image_path;?>" />

I want to iterate through each of them and store the values in an array, I am trying this below, but it isnt going inside the each at all, what am i doing wrong?:

var imageValues = ''; 

jQuery("input[name='image_values']").each(function(){

    imageValues = jQuery(this).val();

});

Thanks

1 Answer 1

2
  • You can use map() for just that. It will return a jQuery collection of that returned in the function. .get() converts this into a normal array.
  • You also need to include the square brackets in your selector, and escape them:
var imageValues = jQuery("input[name='image_values\\[\\]']").map(function(){
        return this.value
}).get()
Sign up to request clarification or add additional context in comments.

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.