views:

43

answers:

2

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?

A: 

To 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

igorp1024
Can we use that structure if you don't use JQuery in your page? I know we use to define ourself a 'GetDocument' function that would return the document depending the browser.
David Brunelle
I am looking for more of an automated way or wiring everything up, I don't want to create a method for every radio button to disable all elements then enable the one
John
BTW, you can consider the following framework: http://www.ixedit.com/They also have video-demo on index page.
igorp1024
A: 

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".

jeffreyveon