Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling radio buttons with jQuery

Tags:

jquery

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'); }); } 
like image 271
user46785 Avatar asked Sep 10 '09 17:09

user46785


People also ask

How can check radio button is disabled in jQuery?

$('#rdStatus'). click(function () { if($(this).is(':enabled')) { // Do enabled radio button code here } else { // Do disabled radio button code here } });


2 Answers

Remove your "each" and just use:

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

That simple. It works

like image 54
KCOtzen Avatar answered Sep 20 '22 12:09

KCOtzen


I've refactored your code a bit, this should work:

jQuery("#loadActive").click(writeData);  function writeData() {     jQuery("#chatTickets input:radio").attr('disabled',true); } 

If there are more than two radio buttons on your form, you'll have to modify the selector, for example, you can use the starts with attribute filter to pick out the radios whose ID starts with ticketID:

function writeData() {     jQuery("#chatTickets input[id^=ticketID]:radio").attr('disabled',true); } 
like image 33
karim79 Avatar answered Sep 21 '22 12:09

karim79