Loop through the ID's instead of doing a switch. This should do the same as yours
function colorM(id){
// if not a number
if (!(!isNaN(parseFloat(n)) && isFinite(n))) id =1;
// default for numbers
if (id > 5 || id < 1) id = 1;
for (var i = 1; i <= 5; i++){
if (id == i){
document.getElementById("slideM" + i).style.backgroundColor="#009CFF";
document.getElementById("slideM" + i).className="show";
document.getElementById("slideC" + i).style.display="block";
}
else {
document.getElementById("slideM" + i).style.backgroundColor="silver";
document.getElementById("slideM" + i).className="";
document.getElementById("slideC" + i).style.display="none";
}
}
}
Edit: added a check if id is numeric id is numeric AND id is within range
Loop through the ID's instead of doing a switch. This should do the same as yours
function colorM(id){
// if not a number
if (!(!isNaN(parseFloat(n)) && isFinite(n))) id =1;
// default for numbers
if (id > 5 || id < 1) id = 1;
for (var i = 1; i <= 5; i++){
if (id == i){
document.getElementById("slideM" + i).style.backgroundColor="#009CFF";
document.getElementById("slideM" + i).className="show";
document.getElementById("slideC" + i).style.display="block";
}
else {
document.getElementById("slideM" + i).style.backgroundColor="silver";
document.getElementById("slideM" + i).className="";
document.getElementById("slideC" + i).style.display="none";
}
}
}
Edit: added a check if id is numeric AND id is within range
Loop through the ID's instead of doing a switch. This should do the same as yours
function colorM(id){
// if not a number
if (!(!isNaN(parseFloat(n)) && isFinite(n))) id =1;
// default for numbers
if (id > 5 || id < 1) id = 1;
for (var i = 1; i <= 5; i++){
if (id == i){
document.getElementById("slideM" + i).style.backgroundColor="#009CFF";
document.getElementById("slideM" + i).className="show";
document.getElementById("slideC" + i).style.display="block";
}
else {
document.getElementById("slideM" + i).style.backgroundColor="silver";
document.getElementById("slideM" + i).className="";
document.getElementById("slideC" + i).style.display="none";
}
}
}
Edit: added a check if id is numeric AND id is within range
Loop through the ID's instead of doing a switch. This should do the same as yours
function colorM(id){
// if not a number
if (!(!isNaN(parseFloat(n)) && isFinite(n))) id =1;
// default for numbers
if (id > 5 || id < 01) id = 1;
for (var i = 1; i <= 5; i++){
if (id == i){
document.getElementById("slideM" + i).style.backgroundColor="#009CFF";
document.getElementById("slideM" + i).className="show";
document.getElementById("slideC" + i).style.display="block";
}
else {
document.getElementById("slideM" + i).style.backgroundColor="silver";
document.getElementById("slideM" + i).className="";
document.getElementById("slideC" + i).style.display="none";
}
}
}
Edit: added a check if id is numeric AND id is within range
Loop through the ID's instead of doing a switch. This should do the same as yours
function colorM(id){
// if not a number
if (!(!isNaN(parseFloat(n)) && isFinite(n))) id =1;
// default for numbers
if (id > 5 || id < 0) id = 1;
for (var i = 1; i <= 5; i++){
if (id == i){
document.getElementById("slideM" + i).style.backgroundColor="#009CFF";
document.getElementById("slideM" + i).className="show";
document.getElementById("slideC" + i).style.display="block";
}
else {
document.getElementById("slideM" + i).style.backgroundColor="silver";
document.getElementById("slideM" + i).className="";
document.getElementById("slideC" + i).style.display="none";
}
}
}
Edit: added a check if id is numeric AND id is within range
Loop through the ID's instead of doing a switch. This should do the same as yours
function colorM(id){
// if not a number
if (!(!isNaN(parseFloat(n)) && isFinite(n))) id =1;
// default for numbers
if (id > 5 || id < 1) id = 1;
for (var i = 1; i <= 5; i++){
if (id == i){
document.getElementById("slideM" + i).style.backgroundColor="#009CFF";
document.getElementById("slideM" + i).className="show";
document.getElementById("slideC" + i).style.display="block";
}
else {
document.getElementById("slideM" + i).style.backgroundColor="silver";
document.getElementById("slideM" + i).className="";
document.getElementById("slideC" + i).style.display="none";
}
}
}
Edit: added a check if id is numeric AND id is within range
Loop through the ID's instead of doing a switch. This should do the same as yours
function colorM(id){
// if not a number
if (!(!isNaN(parseFloat(n)) && isFinite(n))) id =1;
// default for numbers
if (id > 5 || id < 0) id = 1;
for (var i = 1; i <= 5; i++){
if (id == i){
document.getElementById("slideM" + i).style.backgroundColor="#009CFF";
document.getElementById("slideM" + i).className="show";
document.getElementById("slideC" + i).style.display="block";
}
else {
document.getElementById("slideM" + i).style.backgroundColor="silver";
document.getElementById("slideM" + i).className="";
document.getElementById("slideC" + i).style.display="none";
}
}
}
Edit: added a check if id is numeric AND id is within range
Loop through the ID's instead of doing a switch. This should do the same as yours
function colorM(id){
for (var i = 1; i <= 5; i++){
if (id == i){
document.getElementById("slideM" + i).style.backgroundColor="#009CFF";
document.getElementById("slideM" + i).className="show";
document.getElementById("slideC" + i).style.display="block";
}
else {
document.getElementById("slideM" + i).style.backgroundColor="silver";
document.getElementById("slideM" + i).className="";
document.getElementById("slideC" + i).style.display="none";
}
}
}
Loop through the ID's instead of doing a switch. This should do the same as yours
function colorM(id){
// if not a number
if (!(!isNaN(parseFloat(n)) && isFinite(n))) id =1;
// default for numbers
if (id > 5 || id < 0) id = 1;
for (var i = 1; i <= 5; i++){
if (id == i){
document.getElementById("slideM" + i).style.backgroundColor="#009CFF";
document.getElementById("slideM" + i).className="show";
document.getElementById("slideC" + i).style.display="block";
}
else {
document.getElementById("slideM" + i).style.backgroundColor="silver";
document.getElementById("slideM" + i).className="";
document.getElementById("slideC" + i).style.display="none";
}
}
}
Edit: added a check if id is numeric AND id is within range