Alex Rivera | Logout

Disabling radio buttons with jQuery

Asked 2009-09-10T17:10:05.070
57

I'm trying to disable these radio buttons when a the loadActive link is clicked but for some reason it only disables the first in the order and then skips the rest.

<form id="chatTickets" method="post" action="/admin/index.cfm/">
    <input id="ticketID1" type="radio" checked="checked" value="myvalue1" name="ticketID"/>
    <input id="ticketID2" type="radio" checked="checked" value="myvalue2" name="ticketID"/>
</form>
<a href="#" title="Load ActiveChat" id="loadActive">Load Active</a>

And Here is the jquery i'm using:

jQuery("#loadActive").click(function() {
    //I have other code in here that runs before this function call
    writeData();
});
function writeData() {
    jQuery("input[name='ticketID']").each(function(i) {
    jQuery(this).attr('disabled', 'disabled');
});
}
Edit
Report

2 Answers

65

Remove your "each" and just use:

$('input[name=ticketID]').attr("disabled",true);

That simple. It works

answered 2013-04-24T01:16:51.543
3

I just built a sandbox environment with your code and it worked for me. Here is what I used:

<html>
  <head>
    <title>test</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  </head>
  <body>
    <form id="chatTickets" method="post" action="/admin/index.cfm/">
      <input id="ticketID1" type="radio" checked="checked" value="myvalue1" name="ticketID"/>
      <input id="ticketID2" type="radio" checked="checked" value="myvalue2" name="ticketID"/>
    </form>
    <a href="#" title="Load ActiveChat" id="loadActive">Load Active</a>

    <script>
      jQuery("#loadActive").click(function() {
        //I have other code in here that runs before this function call
        writeData();
      });
      function writeData() {
        jQuery("input[name='ticketID']").each(function(i) {
            jQuery(this).attr('disabled', 'disabled');
        });
      }
    </script>
  </body>
</html>

I tested in FF3.5, moving to IE8 now. And it works fine in IE8 too. What browser are you using?

answered 2009-09-10T17:39:34.460

Your Answer