I have the following Yii Booster TbButtonGroup
'buttons' => array(
array('label' => 'Low Danger',
'id' => 'lowDangerButton',
array('label' => 'Mild Danger', 'htmlOptions'=>array('id' => 'mildDangerButton', 'onClick'=>'$("#symptomFlagTextField").val("2");')),
array('label' => 'High Danger', 'htmlOptions'=>array('id' => 'highDangerButton', 'onClick'=>'$("#symptomFlagTextField").val("3");'))
What I want to do is that when the user presses a button, that’s button’s color will change (to something different for each button).
I tried doing it by adding a class to the button (you can see an example of this with the first button), but when I run it it won’t add the class to the button. But the first command in the function ($("#symptomFlagTextField").val(“1”); ) works perfectly.
You missed the hash
Sorry, that was a typo while trying various solutions.
I added the hash back in and it still doesn’t work :/. And I added an alert command to test it out, and it doesn’t work, so it seems when I click the button the only function that works is the val one :S
I tried adding a class to a random div inside the modal the buttonGroup is in, and it also didn’t work for that. I was wondering if something is wrong with jQuery, but the .val() function is working so that’s not it.
Anyway, I just built a seperate js script with a function dothis() inside, and I changed the onClick to:
"onClick" => "js:dothis()"
and it works
Oh, sorry. I don’t know why I haven’t seen it before - you have got there anonymous function that is not called.
Anyway, I’m glad you have solved it.