JZ.
JZ.

Reputation: 21877

Set the Value of a Hidden field using JQuery

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.

Upvotes: 19

Views: 106029

Answers (3)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

The selector should not be #input. That means a field with id="input" which is not your case. You want:

$('#chag_sort').val(sort2);

Or if your hidden input didn't have an unique id but only a name="chag_sort":

$('input[name="chag_sort"]').val(sort2);

Upvotes: 35

Sajidur Rahman
Sajidur Rahman

Reputation: 643

If you have a hidden field like this

  <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("VertragNr") %>'/>

Now you can use your value like this

$(this).parent().find('input[type=hidden]').val()

Upvotes: 2

planetjones
planetjones

Reputation: 12633

Drop the hash - that's for identifying the id attribute.

Upvotes: 3

Related Questions