My webpage has a bunch of radiobuttons across a bunch of different radiobutton groups. Each radiobutton selection which is made will enable a directly corresponding element in the page and disable all other elements which correspond to the other radiobuttons in the group. What is the easiest way to make this link between the elements?
views:
43answers:
2To use javascript-framework like jQuery by adding attribute 'disabled'. For example:
$('#targetElement').attr('disabled', 'disabled');
Also you should keep in mind that it's easier to query for parent element and disable it's child elements.
Also, it's good to wait for the document being loaded and then add click-handlers on the radio controls
If you really want a slick way to do something like that, you should look into the eval(). It will allow you to dynamically execute a piece of code, based on a string. So, in your case, you can store this relation (maybe the ID of the corresponding element) as an attribute and then when any radio button is click. You extract this particular attribute and make an expression and eval() it to get it hide:
e.g. using jQuery:
eval( '$("#"' + some_attr + '").show()' );
However, this is generally not considered a good practise, but is pretty "automated".