SACHIN GAJBHIYE SACHIN GAJBHIYE - 1 year ago 37
jQuery Question

radio button not shows updated value

I'm trying to update values from form except gender value all updates.
Gender value is not updating
here is code for gender radio button.

<label>
Gender: </label>
<input type="radio" id="gender" name="gender" value="male" required> Male
<input type="radio" name="gender" id="gender" value="female" required> Female
<input type="radio" name="gender" id="gender" value="other" required> Other


I'fetching value of form using js function which send it to update function.

var gender = $('#gender').val();


what mistake I had made?

Answer Source

This should work

// Get the value from a set of radio buttons
$('input:radio[name="gender"]:checked').val();

See also the examples given at http://api.jquery.com/val/