select - How do I say 'and/or' in jQuery? -


i have can't head around... been trying quite while already.

i have snippet of jquery:

$("#amp").on('change', function () {      $("#cab").prop('disabled', $(this).val() == "combo models - 22w");     $("#cab option").prop("selected", true); }); 

i need duplicate exact bit of code 4 times need change 'combo models - 22w' 4 different things.

i tried duplicating code 4 times , changing property didn't work.

is there way of saying like:

$("#cab").prop('disabled', $(this).val() == "combo models - 22w" or "combo models - 50w" or "combo models - 75w");   

...but snippet works? thanks!

you store values in hash map. this:

var map = {}; map["combo models - 22w"] = true; map["combo models - 50w"] = true; map["combo models - 75w"] = true; 

and on.

then use:

$("#cab").prop('disabled', false || map[$(this).val()]); 

if string obtained using map[$(this).val() in hash map, map[$(this).val() evaluates true. otherwise evaluates undefined. false || undefined part becomes simple, explicit false.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -