I'm trying to accomplish the following with Jquery:
When the "No Top" radio-button is "checked" it should disable and "uncheck" any selection done in the Checkbox selection.
If the user select another radio-button option for example "Black Top", the Checkbox selection should be enabled again.
I'm trying to solve this problem but can't figure out how to find the correct radio-button or checkbox using the labels text (that's all I have to go on). I can't use the ID's because it renders with different names all the time.
Clarification: The first div class "option-box" contains the radio set which then follows a second div class "option-box" with the checkboxes. The page have more controls both radio and checkboxes but it is just the checkboxes inside the second "option-class" I'm trying to manipulate.
Any ides?
Here is the code that my controls generate (which I cant modify):
<div class="option-box">
<div class="radio">
<label>
<input id="ctl00_PageContent_ctl00_KitsList_ctl03_KitComponent_4_0" name="ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4" value="0" checked="checked" type="radio" />
No Top
</label>
</div>
<div class="radio">
<label>
<input id="ctl00_PageContent_ctl00_KitsList_ctl03_KitComponent_4_1" name="ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4" value="8" onclick="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4$1\',\'\')', 0)" type="radio" />
Black Top
</label>
</div>
<div class="radio">
<label>
<input id="ctl00_PageContent_ctl00_KitsList_ctl03_KitComponent_4_2" name="ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4" value="9" onclick="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4$2\',\'\')', 0)" type="radio" />
White Top
</label>
</div>
<div class="radio">
<label>
<input id="ctl00_PageContent_ctl00_KitsList_ctl03_KitComponent_4_3" name="ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4" value="10" onclick="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$ctl00$KitsList$ctl03$KitComponent_4$3\',\'\')', 0)" type="radio" />
Silver Top
</label>
</div>
</div>
<div class="option-box">
<div class="checkbox">
<label>
<input id="ctl00_PageContent_ctl00_KitsList_ctl04_KitComponent_10_0" name="ctl00$PageContent$ctl00$KitsList$ctl04$KitComponent_10$0" onclick="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$ctl00$KitsList$ctl04$KitComponent_10$0\',\'\')', 0)" value="11" type="checkbox" />
Backdoor
</label>
</div>
<div class="checkbox">
<label>
<input id="ctl00_PageContent_ctl00_KitsList_ctl04_KitComponent_10_1" name="ctl00$PageContent$ctl00$KitsList$ctl04$KitComponent_10$1" onclick="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$ctl00$KitsList$ctl04$KitComponent_10$1\',\'\')', 0)" value="12" type="checkbox" />
Topdoor
</label>
</div>
</div>
You can differentiate the inputs by their type
attribute, something like this:
$('.option-box input[type="radio"]').change(function() {
$('.option-box input[type="checkbox"]').prop({
'disabled': $(this).val() == "0",
'checked': false
});
});
If there are multiple copies of this .option-box
structure in the page you can use DOM traversal to find the one related to that which raised the event:
$('.option-box input[type="radio"]').change(function() {
$(this).closest('.option-box').next('.option-box').find('input[type="checkbox"]').prop({
'disabled': $(this).val() == "0",
'checked': false
});
});
If you cannot use any id nor the input VALUE, you can try like this
$(document).ready(function () {
$( '.option-box' ).on( 'click', 'input[type="radio"]', function() {
var labelContent = $( this ).parents(".radio").find( "label" ).html();
if( labelContent.indexOf( "No Top" ) > -1 ) {
$( ".checkbox input" ).attr( "disabled", "disabled" ).removeAttr( "checked" );
} else {
$( ".checkbox input" ).removeAttr( "disabled" );
}
});
});
I want to create paragraph dynamic,so I wrote the following code. After user click the button, a new paragraph whose innerText is the user's inputs should be added.But I failed, Is there someone can ...
I want to create paragraph dynamic,so I wrote the following code. After user click the button, a new paragraph whose innerText is the user's inputs should be added.But I failed, Is there someone can ...
I'm trying to create a news style marquee at the bottom of my XSL page that shows some information it retrieves from an XML file. What I want it to do is automatically refresh the content of only this ...
I'm trying to create a news style marquee at the bottom of my XSL page that shows some information it retrieves from an XML file. What I want it to do is automatically refresh the content of only this ...
I have an array of letters and numbers. let sortLetters = [ 'R', '1', 'U', '1', 'N', '1', 'D', '1', 'M', '1', 'C', '1' ] I want to sort the types alphabetically, then return the first letter I come ...
I have an array of letters and numbers. let sortLetters = [ 'R', '1', 'U', '1', 'N', '1', 'D', '1', 'M', '1', 'C', '1' ] I want to sort the types alphabetically, then return the first letter I come ...
Hello I am taking an array of integers with ranging numbers from 1 - 100 and I'm counting the duplicated numbers within it. Example, array[1,1,1,1,1,100,3,5,2,5,2,23,23,23,23,23,]. Result = 1 - 5 ...
Hello I am taking an array of integers with ranging numbers from 1 - 100 and I'm counting the duplicated numbers within it. Example, array[1,1,1,1,1,100,3,5,2,5,2,23,23,23,23,23,]. Result = 1 - 5 ...