I've got the following code which depending on a url parameter changes and then hides a select option on a form. ie www.example.com?type=images
Eventually there will be over 20 different parameters. I'd like to know of a better way than having a huge amount of if elses. Just an outline of how to do it is fine, I'm new to this, so I'd like to be able to take the answer and learn from it. Thanks.
var type = getURLparameter('type'); //from another function
if (type == "images"){
var selectDiv =('divid');
var selectField = ('selectid');
document.getElementById(selectField).options[1].selected=true;
document.getElementById(selectDiv).style.visibility="hidden";
}
else if (type == "pizza") {
var selectDiv =('divid');
var selectField = ('selectid');
document.getElementById(selectField).options[2].selected=true;
document.getElementById(selectDiv).style.visibility="hidden";
}
else (type == "cheese") {
var selectDiv =('divid');
var selectField = ('selectid');
document.getElementById(selectField).options[3].selected=true;
document.getElementById(selectDiv).style.visibility="hidden";
}