Managing a massive IF statement in jQuery
I have an if statement that has over 100 different if's.
at the minute im using something similar to this...
$('select').on("change",function(){
if( $(this).val() === 'tennis' ) {
$('.sport').val('raquet');
}
else if( $(this).val() === 'soccer' ) {
$('.sport').val('goal');
}
if( $(this).val() === 'snooker' ) {
$('.sport').val('cue');
}
});
I want to build one for counties in the uk, so if a user selects 'london'
in the dropdown, the next field is populated with the postcode for london.
My problem is however, I could build it as my above example, only it would
be huge.
Is it possible to have some sort of xml file to do this? or would it be
possible to put each county and its value into an object inside an array
and target it this way?
Any help is greatly appreciated, thanks
http://jsfiddle.net/4xQeX/
No comments:
Post a Comment