views:

3023

answers:

6

Hello all,

I have group of radio buttons. I want to uncheck the check buttons after an ajax form submitted. I have the following function:

function clearForm(){
  $('#frm input[type="text"]').each(function(){
      $(this).val("");  
  });
  $('#frm input[type="radio":checked]').each(function(){
      $(this).checked = false;  
  });
 }

With the help of this function i can clear the values at the textboxes. But i can't clear the values at the radio button. BTW i also tried $(this).val(""); but got no use.

Thanx

+1  A: 

Try

$(this).attr("checked" , false );
rahul
+6  A: 

either (plain js)

this.checked = false;

or (jQuery)

$(this).attr('checked', false);
David Hedlund
+4  A: 

You wouldn't need the each function

$("input:radio").attr("checked", false);

Or

$("input:radio").removeAttr("checked");

The same should also apply to your textbox:

$('#frm input[type="text"]').val("");

But you could improve this

$('#frm input:text').val("");
James Wiseman
+3  A: 

Try

$(this).removeAttr('checked')

Since a lot of browsers will interpret 'checked=anything' as true. This will remove the checked attribute altogether.

Hope this helps.

cjstehno
Also, as one of the other answers mentions, you wont need the each function; you could just chain the removeAttr call to the selector.
cjstehno
+1  A: 

Try this, this will do the trick:

        $(document).ready(function() {
           $("input[type='radio']").mousedown(function(e) {
                if ($(this).attr("checked") == true) {
                   setTimeout("$('input[id=" + $(this).attr('id') + "]').removeAttr('checked');", 200);}
                else {
                    return true
                }
            });
        });
Patrick Rietveld