1

I want to Validate Radio Button List in asp.net using jquery, where I am having radio button list in child page, and I need to show alert box when user never selects any option

Here is the code, which I have tried.

$(function(){ 
    $("#<%=btnSave.ClientID %>").click(function(){
          var v=$("#<%=rdTax.ClientID %>input:checked").val(); 
     }); 
});
3
  • show some code ,what have you tried? Commented Sep 28, 2012 at 10:56
  • I tried above code but i could not find it... Commented Sep 28, 2012 at 10:57
  • Do you have space between %> and input:checked or not? Commented Sep 28, 2012 at 11:02

3 Answers 3

3

Your code should like this

$(function(){ 
    $("#<%=btnSave.ClientID %>").click(function(){
          var v=$("#<%=rdTax.ClientID %> input:checked").length;
          if(v==0)
             alert('Not checked any radio button');
     }); 
});

or better you can try this

$(function(){ 
    $("[id$=btnSave]").click(function(){
          var v=$("[id$=rdTax]").find("input:checked").length;
          if(v==0)
             alert('Not checked any radio button');
     }); 
});
Sign up to request clarification or add additional context in comments.

1 Comment

@PramodSawant mark answer as correct answer if it's working for you
1

Use length to check if any radiobutton is checked ,length would be zero if no button is selected

$('input[type=radio][name=radiobuttonlistID]:checked').length  

and use prop to check or uncheck them

$('input[type=radio][name="radiobuttonlistID"]').prop('checked', false);

Comments

0

Easy way to validate a radio button set the default selection of radio button when you want. I think this is a best way to validate radio button.

If you want to use jquery validation plugin see a link:

http://jquery.bassistance.de/validate/demo/radio-checkbox-select-demo.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.