0

I have some hidden input fields like this ...

<input type="hidden" class="added_ids[]" name="added_ids[]" value="5190">
<input type="hidden" class="added_ids[]" name="added_ids[]" value="5340">
<input type="hidden" class="added_ids[]" name="added_ids[]" value="2488">

....and so on.

I need to get the values of each of the input fields so that I can pass it as a parameter to my php page.

url: "index.php/autocomplete/test_search?added_ids[]=" + //array holding ids

so I need to know how I do it in jQuery ..

1
  • looks like you would have better to serialize it: var values = $(':hidden').serialize(); jsfiddle.net/hd58F Gives you a parameters string that can be passed to server Commented Jan 9, 2014 at 10:49

2 Answers 2

1

try something like this

var array = $('.added_ids\\[\\]').map(function() {
    return this.value;
}).get();
console.log(array); \\will give you ["5190", "5340", "2488"]
Sign up to request clarification or add additional context in comments.

Comments

0

You can use map():

var added_ids = $('.added_ids\\[\\]').map(function() {
    return this.value;
}).get();
var url = "index.php/autocomplete/test_search?added_ids[]=" + added_ids.join();

In your PHP you can then retrieve the value and split it by , to return it back to an array.

4 Comments

@RoryMcCrossan why double slashes? ('\\')
@RoryMcCrossan It is passing null. localhost/project/index.php/dearch/…
@JensonMJohn the slashes escape the square bracket character which would break the selector otherwise.
@user3177114 I cannot access anything hosted on your localhost.

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.