jQuery buttonset change

19,536

Solution 1

Ha! Problem solved. I've been hacking at this all day, and it was right in front of me.

I just needed to change how I was selecting the element to this:

$('#tod_quant')

Solution 2

There's no change event for buttons in jQuery-UI.

You should listen to change or click event of the underlying radio-buttons:

http://jsfiddle.net/marcosfromero/kr2Xc/

Solution 3

I had this problem, and I solved this as below: I created an event handler for labels:

$('.label-class').click(LabelClicked);
$('.input-class').change(InputChanged);
function LabelClicked() {
    var input = $('#' + $(this).attr('for'));
    if(input) 
        input.trigger('change'); 
    return true;
}
function InputChanged() {
    //do your work with this event
}

no other way! I tested several ways and finally decided to do this

Share:
19,536
Brad
Author by

Brad

Software engineer. Web evangelist. Core competencies include: Audio Streaming Media Teaching Oddball cross-systems integration Newfangled browser APIs and standards I like to work on strange projects that enable people to do things in the real world that would be otherwise difficult or impossible. Want to integrate GNSS with sonar sensors to make 3D maps of a river bed? How about control MIDI synthesizers and DMX lighting with your brainwaves? Perhaps you just want to build and deploy something reliable and scalable without unnecessary complexity? This is what I do. I also like to teach others anything I can. I embed well with existing teams and can help up-level developers' skills in areas I have knowledge of. Do you already have an effective web team that needs help adding streaming audio/video to your site? Invite me to meet your folks to see if I can assist. I am available for consulting. You may contact me at [email protected]. Thank you!

Updated on June 04, 2022

Comments

  • Brad
    Brad about 2 years

    I'm new to jQuery and thought I would use its buttonset instead of some radio buttons on my application. Documentation here: http://jqueryui.com/demos/button/#radio

    How do I add a handler to an event when the set of buttons changes value?

    Here is a snippet of the code I tried:

    $('input.tod_quant').change(function() {
        alert('TEST');
    });
    

    And then later on in the HTML:

    <span id="tod_quant" class="buttonset">
            <input type="radio" id="tod_quant5" name="tod_quant" value="5" /><label for="tod_quant5">5-Minute</label>
            <input type="radio" id="tod_quant60" name="tod_quant" checked="checked" value="60" /><label for="tod_quant60">60-Minute</label>
            </span>
    

    The "change" event never fires. Is there even a change event? How can I do this? Furthermore, is there any documentation with an example? http://jqueryui.com has plenty of examples, and not a single one that I can find shows any events firing. I suppose my ignorance of jQuery isn't exactly helping the situation.

    Any help would be most appreciated. Thank you.