vimal1083
vimal1083

Reputation: 8661

How to select a input with name and value

I need to select a radio input with name and value in jquery

In this example how you select element with name SiblingSex and value female

<form action="">
<input type="radio"  name="SiblingSex" value="male">Male<br>
<input type="radio"  name="SiblingSex" value="female">Female


<input type="radio"  name="ParentSex" value="male">Male<br>
<input type="radio"  name="ParentSex" value="female">Female

</form>

i need some thing like

$('input[name="SiblingSex"]' /*GENDER SELECTOR */)

Upvotes: 0

Views: 140

Answers (2)

Jai
Jai

Reputation: 74738

You can add another attribute selector with this:

$('input[name="SiblingSex"][value="female"]').val();

the above line would give you values every time whether it is checked or not.

so if you only want to have the value when it is checked too then add :checked

$('input[name="SiblingSex"][value="female"]:checked').val();

Upvotes: 1

Rahul
Rahul

Reputation: 2307

Just have a look on the Demo on my JS Fiddle Code

Shows the two scenario:

1) when you want the value without selecting radio button.


2) when you want value after selecting radio button.

or may be the thing that you want is here::

JS Fiddle Demo

Upvotes: 1

Related Questions