Reputation: 5411
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.
Upvotes: 0
Views: 45
Reputation: 2368
You have wrong selector. Try this
$('input[name="associations[agencies][ids][]"]').val();
Upvotes: 1
Reputation: 1362
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()
Upvotes: 1
Reputation: 2890
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][]']")
Upvotes: 1
Reputation: 1263
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 ;)
Upvotes: 1