A few notes... "==" is the comparison operator, not the assignment operator. "=" is the assignment operator.
$().val is a *method*, not a property. $().val() retrieves the value, and $().val(newvalue) sets the value. (So you wouldn't want to use the assignment operator anyway.) You're setting a global variable "$this", which is likely not what you want. Use "var" to create a local variable. When you find yourself writing the same line of code twice, look for a way to combine them. Personally I would probably code it like this: $(pselectBox).change(function () { var val = $(this).val(); $("#chkneededby").val( val == 'Urgent' || val == 'Critical' ? $('#dateSel').val() : '01/01/2999' ); }); Hope that helps, -Mike > Quick question regarding retrieving a field value. I have > the following code. Basically based on a select menu option I > want to set a hidden field to specific value depending on > what is selected. > > So if the user selects Urgent or Critical the hidden field > would be set to the value of another field in the form. I am > trying to use $ ("#chkneededby").val == $('#dateSel').val; > but that does not seem to work. > > Is this correct if say I want to get the field value of a > field with the id dateSel $('#dateSel').val; > > $(pselectBox).change(function () { > // var text = $(this).text(); > $this = $(this); > if ($this.val() == 'Urgent') { > $("#chkneededby").val == $('#dateSel').val; > } else if ($this.val() == 'Critical') { > $("#chkneededby").val == $('#dateSel').val; > } else { > $("#chkneededby").val('01/01/2999'); > } > }); >