views:

37

answers:

3

I have the following code:

<td><input class="publish" id="publish_company_ids" name="publish_company_ids[]" type="checkbox" value="1" /></td>

<td><input class="discard" id="discard_company_ids" name="discard_company_ids[]" type="checkbox" value="1" /></td>

I'd like when I click the first checkbox, the second checkbox to become disabled. I am trying this jquery code:

$(".publish").click(function () { 
 $(this).parent().next("td > input[text='checkbox']").css("border","1px solid green");
});

I tried by changing css border but it doesn't work.

+1  A: 

First, you have text instead of type in your selector.

Second, if that doesn't help, try this:

$(this).parent().next('td').children('input:checkbox').css('border','1px solid green');
Jeff Rupert
It worked, just it didn't want the css change (it didn't apply the border), so I replace it with toggle() and it worked. I tried many things but only this one is working. Thank you
JohnDel
You're welcome! =)
Jeff Rupert
+1  A: 

If you want to allow users to select only one of the checkbox then you should radio button instead of checkbox.

Maulik Vora
If I add radio buttons, I'll have to add 3 radio, in case someone wants to deselect the option.
JohnDel
You don't have to add three radio, but you don't need to make any radio selected by default. thats it. You will have three result. one publish_company_ids , discard_company_ids and null, you will not get any value..
Maulik Vora
I'll have to add it in case a user accidentally select an option and wants after to deselect it.
JohnDel
@JohnDel yeps....
Maulik Vora
A: 

Try:

$(".publish").click(function () { 
 $(this).parent().find("input.discard").css("border","1px solid green");
});

Or:

$(".publish").click(function () { 
 $(this).parent().children("input.discard").css("border","1px solid green");
});
Sarfraz