im trying to add a class on the fly to an input, if the selected value equals a certain value.
$("#schedule_event").chosen().change( function() {
$('#1').slideUp();
$('#2').slideUp();
$('#3').slideUp();
$('#' + $(this).val()).slideDown();
if($(this).val == 1) {
$("#schedule_opponent_id").addClass("required");
}
or if there is a way of validating this through RoR validators would be great
thanks
You have the right approach but
valis a method not a property (therefore you need to add()to invoke it). You should probably also remove the class if your criteria isn’t met. That way if the field is changed to an option with a value other than1the#schedule_opponent_idfield will no longer have therequiredclass.