SACHIN GAJBHIYE SACHIN GAJBHIYE - 4 months ago 10
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

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/