Skip Navigation Links



Validate ASP.NET RadioButtonList using jQuery

Author : Virendra Dugar      Blog :jQuery By Example      Date: 7/4/2012 4:30:00 AM


ASP.NET RadioButtonList control is used to create a group of radio buttons, where all are rendered as an individual <input type=radio></input>. So in this post, I will show you how to validate ASP.NET RadioButtonList using jQuery.

Let's declare a RadioButtonList.
<asp:RadioButtonList ID="rdlList" runat="server">
    <asp:ListItem Text="jQuery" Value="jQuery"></asp:ListItem>
    <asp:ListItem Text="JavaScript" Value="JavaScript"></asp:ListItem>
    <asp:ListItem Text="Prototype" Value="Prototype"></asp:ListItem>
    <asp:ListItem Text="Dojo" Value="Dojo"></asp:ListItem>
    <asp:ListItem Text="Mootools" Value="Mootools"></asp:ListItem>
</asp:RadioButtonList>
As you can see there are 5 radio buttons and the validation would be to select at least one option. For demo, I will validate the radiobuttonlist on click of button. We can use length property to find out, if any radio button is selected or not.

$("#rdlList :radio:checked").length; will return 1 if anything is selected, otherwise 0.
$(document).ready(function() {
    $('#btnSubmit').on('click', function(e) {
        var cnt = $("#rdlList :radio:checked").length;
        if (cnt == 0) 
        {
            alert('Select any option.');
            e.preventDefault();
        }
        else 
            alert('Well Done!!!!');
    });
});​
Note: This code will work only with jQuery 1.7 or higher version as I have used .on() method to bind the click event and .on was introduced in jQuery 1.7. So if you are using below version then you can either .live() or .bind() method.

Suggested Post,
Feel free to contact me for any help related to jQuery, I will gladly help you.

Bloggers

active bloggers in the last 24 hrs. Number shown in the bracket represents number of posts published in past 24 hrs,


other authors(63)

Fidarose Isha(3)

N.GURURAJ.(3)

ravi dabas(3)

sankarshan(3)

Srinivasan Sampathkumar(3)

Ambica Srimal(2)

AMJAD KHAN(2)

Deepak(2)

Firoze Shakir Photographerno1(2)

Praveen Battula(2)

R.D. Bhalekar(2)

Rakesh HP(2)

Raksha(2)

Vikram Karve(2)

- Sugar Cube -(1)

Aarthi(1)

Aathira Nair(1)

Amarendra(1)

Anil(1)

Anu Lal(1)

Anu Varma(1)

Anuradha Goyal(1)

Aparna(1)

Aparna(1)

Archana Kumar(1)

Aruna Manikandan(1)

aseemrastogi2(1)

Ashwini Kumar(1)

Bombay Chowparty(1)

Champa(1)

Chandrika Shubham(1)

churumuri(1)

churumuri(1)

Cynthia Z(1)

Daksha(1)

Deeps(1)

Devi(1)

Dew(1)

Divya Kudua(1)

Dr.K.P.R.RAJA(1)

Erin W.(1)

Garfield Dsouza(1)

Geek Girl(1)

Hamaree Rasoi(1)

Harimohan(1)

Harini Padmanabhan(1)

harish p i(1)

Hemu(1)

Ibrahim(1)

IS(1)

Jean(1)

Kaveri Venkatesh(1)

Krithi Karthi(1)

Kumar Harsheet Raj(1)

Kunal Singh(1)

Love Baronia(1)

Madhavi Madhurakavi(1)

mahima(1)

Manreet Sodhi Someshwar(1)

Meena(1)

Megha Sarin(1)

mêlée(1)

MUNZ TDT(1)

Mythreyi(1)

Nagendra Bharathi(1)

Nandana(1)

Neelam Dadhwal(1)

Neeraja(1)

Nisha(1)

Nona(1)

nourishncherish(1)

Nupur(1)

palash ranjan khound(1)

parth joshi(1)

Patricia Torres(1)

pinksocks(1)

Pradeep Chakraborty(1)

Pranshu(1)

Prasanta Bora(1)

Preety(1)

Priyadarshi Mishra(1)

Raafay Awan(1)

Raja(1)

Rams(1)

rhythmnguitars(1)

Ritesh Agarwal(1)

Ritu(1)

RWABhagidari.blogspot.com(1)

saketvaani(1)

Sampada(1)

Sandhya(1)

Santhosh Sivarajan(1)

Sayantani(1)

Shobha(1)

Sneo(1)

Sravs(1)

Sree(1)

Sreedhar Jeshurun(1)

Sriram Khé(1)

Sudharsan Narayanan(1)

Sujoy Das(1)

Team G Square(1)

the blogger formerly known as sansmerci(1)

The Guy in the Hat ™(1)

unmanagedexe(1)

Vaishali(1)

vanya(1)

Vashi Chandiramani(1)

Vasudev Ram(1)

VJ Sharma(1)


garland of Languages of India
an amalgamation of the diversified traditions
gracefully presented with novelty
http://www.haaram.com