Forgot one line, which will get it to synchronize state at the page load, too:
var synchronize_labels = function(){
$$('input[type="radio"]').each(function(elm){
if(elm.checked){
elm.up('label').addClassName('checked-appearance');
}else{
elm.up('label').removeClassName('checked-appearance');
}
});
};
synchronize_labels();
document.on('click', synchronize_labels);
All of this should be inside the event listener for the page load. If you are using the Protaculous 2 Action to add this to your page, just put it in the DOM Loaded Observer editor in that Action. If you are hand-coding this, then you would do this, inside a script block, either in the page head or at the bottom of the body:
document.observe('dom:loaded', function(){
// paste all that code here
});
Walter
On Nov 4, 2015, at 7:26 AM, Walter Lee Davis email@hidden wrote:
If you want the label associated with a particular checkbox or radio button to change depending on the state of the input, you are probably going to have to break out some JavaScript for that. I am not aware of a CSS selector that can use a child element (and thus its state) to select the parent. It’s been wished for many many times, and hasn’t come true yet.
In Prototype:
var synchronize_labels = function(){
$$('input[type="radio"]').each(function(elm){
if(elm.checked){
elm.up('label').addClassName('checked-appearance');
}else{
elm.up('label').removeClassName('checked-appearance');
}
});
};
document.on('click', synchronize_labels);
This assumes that you are wrapping labels around your inputs, as is the best practice for something as small as a radio button.
Walter
On Nov 4, 2015, at 3:41 AM, Frans Boumans email@hidden wrote:
Thanks! Still, what if I want the label to change? How can I change it’s color when the button is checked?
freewaytalk mailing list
email@hidden
Update your subscriptions at:
https://freewaytalk.softpress.com/person/options
freewaytalk mailing list
email@hidden
Update your subscriptions at:
https://freewaytalk.softpress.com/person/options
freewaytalk mailing list
email@hidden
Update your subscriptions at:
https://freewaytalk.softpress.com/person/options