Reputation: 2261
Hi I am trying to assign the value from a select input to a hidden field using jquery, although I keep receiving an invalid left hand side of operator. I tried using the hiddenProgramIds.ClientId, but only received an error. Can someone shed a little light. Thanks.
$("#programSelector").on('click', function addProgram() {
$("<%= hiddenProgramIds %>").val() = $('#programSelector').val();
});
<asp:HiddenField ID="hiddenProgramIds" runat="server" Value="" />
Upvotes: 1
Views: 16649
Reputation: 318342
You don't set a value with =
in jQuery, you pass the string as an argument to the val()
function, like this
$("#programSelector").on('change', function() {
$("#<%= hiddenProgramIds.ClientID %>").val( this.value );
});
and if #programSelector is in fact a select element, you should be using the change
event, not click
Upvotes: 7
Reputation: 1159
You need use ClientId to JQuery works
$("#<%= hiddenProgramIds.ClientID %>").val( this.value );
Upvotes: 1