0

I have the following input

<input value="25" data-hidden-value="25" name="associations[agencies][ids][]" 
           data-hidden-name="associations[agencies][ids][]" class="string" type="hidden">

This input is dynamically generated, and don't have any ID. I'm trying to get the value using the following code:

campaignId = $("input[name='associations[agencies][ids][]]'").val();

But I always get undefined.

4 Answers 4

1

You have wrong selector. Try this

$('input[name="associations[agencies][ids][]"]').val();
Sign up to request clarification or add additional context in comments.

Comments

1

The problem is with your selector - you closed the first opening [ in the wrong place. Proper line should be:

campaignId = $("input[name='associations[agencies][ids][]']").val();

Hope that helps ;)

Comments

1

You have a syntax error at input[name='xxx'] , the last single quote should be inside the last ]

change

$("input[name='associations[agencies][ids][]]'")

to

$("input[name='associations[agencies][ids][]']")

Comments

1

you just need to change the value of name that you are provided $("input[name='xyz']") you just misplace the ] inside the '

$("input[name='associations[agencies][ids][]]'").val()

to

 $("input[name='associations[agencies][ids][]']").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.