I want to set the value of a hidden field, using JQuery.
Hidden Field:
<input id="chag_sort" type="hidden" name="chag_sort">
My JQuery:
$("#input[name=chag_sort]").val(sort2);
What am I doing wrong? I should also mention in console that sort2 does in fact have a value: DESC.
Drop the hash - that's for identifying the id attribute.
The selector should not be
#input
. That means a field withid="input"
which is not your case. You want:Or if your hidden input didn't have an unique id but only a
name="chag_sort"
:If you have a hidden field like this
Now you can use your value like this
$(this).parent().find('input[type=hidden]').val()