SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    737
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Question jQuery and Radio Buttons

    Hi,

    I have a couple of radio buttons all under 1 single group.

    I want an alert box on click of a button that will say if any of the radio button is checked or not.

    Can u help plz?


    Thanx a ton

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    The traversing selectors page shows you how to do that.

    Code html4strict:
    <html>
    <head>
    <title>Test</title>
    </head>
    <body>
    <fieldset id="myRadios">
    <input type="radio" name="myradio" id="radio1">
    <input type="radio" name="myradio" id="radio2">
    <input type="radio" name="myradio" id="radio3">
    <input type="button" id="radioStatus" value="Radio Status">
    </fieldset>
    <script src="jquery-1.2.6.min.js"></script>
    <script>
    document.getElementById('radioStatus').onclick = function () {
        if ($('#myRadios input[@type=radio][@checked]').length) {
            alert("A radio button is checked");
        } else {
            alert("No radio button is checked");
        }
    };
    </script>
    </body>
    </html>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •