Oh, neat idea for some quick prototypes if you'll be using this a lot. String.prototype.is = function(){ var rgx = new RegExp('^' + [].slice.call(arguments).join("|") + '$'); return rgx.test(this) }
Should mimic: /^A|B|C$/.test( $('#price_group_lesson').val() ); Called by: $('#price_group_lesson').val().is('A','B','C','D'); On Jan 22, 9:00 am, pixelwiz <pixel...@gmail.com> wrote: > That's some cool code. Thanks Guys! > > -Roman > > On Jan 21, 11:49 pm, Ricardo Tomasi <ricardob...@gmail.com> wrote: > > > var abc = /^A|B|C$/.test( $('#price_group_lesson').val() ); > > $('#price_group_lesson_yes')[abc ? 'slideDown' : 'slideUp']('fast') > > > (it could be a one-liner but I splitted it for readability) > > > A simpler improvement you could have done: > > > var p = $('#price_group_lesson').val(); > > if ( p == 'A' || p == 'B' || p == 'C' ) > > $('#price_group_lesson_yes').slideDown('fast'); > > else > > $('#price_group_lesson_yes').slideUp('fast'); > > > or > > > var p = $('#price_group_lesson').val(); > > ( p == 'A' || p == 'B' || p == 'C' ) > > ? $('#price_group_lesson_yes').slideDown('fast') //if > > : $('#price_group_lesson_yes').slideUp('fast'); //else > > > Or to top it off, a hacky way of checking the value: > > > ($('#price_group_lesson').val() in {A:1, B:1, C:1}) > > ? $('#price_group_lesson_yes').slideDown('fast') > > : $('#price_group_lesson_yes').slideUp('fast'); > > > - ricardo > > > On Jan 21, 7:15 pm, pixelwiz <pixel...@gmail.com> wrote: > > > > Hi All, I am sure this is an easy question for someone in here. Is > > > there a better, cleaner, shorter way to write this: > > > > if ( ($('#price_group_lesson').attr("value") == 'B') || ($ > > > ('#price_group_lesson').attr("value") == 'C') || ($ > > > ('#price_group_lesson').attr("value") == 'D') ){ > > > > > > $('#price_group_lesson_yes').slideDown('fast');} > > > > > > else{$('#price_group_lesson_yes').slideUp('fast');} > > > > I am creating a pretty custom questionnaire, and it has a lot of logic > > > in it. I wish I didn't have to type it all out like that. I am sure > > > there is something in javascript or jquery where I can say $ > > > ('#var').attr('value').in("A","B","C") > > > > Thanks