jQuery and multiple radio buttons

JackTheKnife

Limp Gawd
Joined
Mar 27, 2006
Messages
272
I have something like:

Code:
    <!DOCTYPE html>
    <html>
    <head>
      <style>
    input, label { line-height: 1.5em; }
    </style>
      <script src="http://code.jquery.com/jquery-latest.js"></script>
    </head>
    <body>
      
    <form> 

    <div>
      <div>
        <input type="radio" name="rb_1" value="high" id="hi">
        <label for="f11">f11</label>
      </div>
      <div>
        <input type="radio" name="rb_1" value="middle" id="mid">
        <label for="f12">f12</label>
      </div>
      <div>
        <input type="radio" name="rb_1" value="lower" id="lo">
        <label for="f13">f13</label>
      </div>
     </div>

      <div>
        <input type="radio" name="rb_2" value="high" id="hi">
        <label for="f21">f21</label>
      </div>
      <div>
        <input type="radio" name="rb_2" value="middle" id="mid">
        <label for="f22">f22</label>
      </div>
      <div>
        <input type="radio" name="rb_2" value="lower" id="lo">
        <label for="f23">f23</label>
      </div>
     </div> 

      <div>
        <input type="radio" name="rb_x" value="high" id="hi">
        <label for="fx1">fx1</label>
      </div>
      <div>
        <input type="radio" name="rb_x" value="middle" id="mid">
        <label for="fx2">fx2</label>
      </div>
      <div>
        <input type="radio" name="rb_x" value="lower" id="lo">
        <label for="fx3">fx3</label>
      </div>
     </div>

      <div id="log"></div>
    </form>

    <script>
    $("input").click(function() {
      $("#log").html( $(":checked").val() + " is checked!" );
    });
    </script>

    </body>
    </html>

Somehow I can't get this to work. Any idea why? Thanks.
 
try changing
$("#log").html( $(":checked").val() + " is checked!" );
to

$("#log").html( $(this).val + " is checked!" );
 
Last edited:
Back
Top