Kledi
Kledi

Reputation: 23

clear checked radio button value from form

I have this piece of code which represents a few radio buttons.

<label>Tipologia Pdv: </label>
<input type="radio" name="tipologia_pdv" id="tipologia_pdv" value="Iper" style="width:40px;" /><span > Iper</span>
<input type="radio" name="tipologia_pdv" id="tipologia_pdv"
value="Super" style="width:40px;" /><span > Super</span>

Then, i have this code which clears the value, but it doesnt work with radio buttons:

  $("#tipologia_pdv").val('');

Now, how would i get the to clear the checked value here? I assign the checked value with this and it works:

var js_tipologia_pdv = $('input:radio[name=tipologia_pdv]:checked').val();

Upvotes: 0

Views: 294

Answers (3)

Sushanth --
Sushanth --

Reputation: 55740

I see that the two radio buttons have the same id. ID should be unique..

The checked property is different than the val property .. To uncheck it you have to do this

var js_tipologia_pdv = $('input:radio[name=tipologia_pdv]:checked');

 js_tipologia_pdv.prop('checked', false);

check FIDDLE

Upvotes: 0

Riz
Riz

Reputation: 10246

$("#tipologia_pdv").prop("checked", false);

http://api.jquery.com/prop/

Upvotes: 0

Tom
Tom

Reputation: 3040

$('#tipologia_pdv').attr('checked', false);

Prop works also

$('#tipologia_pdv').prop('checked', false);

Upvotes: 1

Related Questions