I'd created checkDay function for get value of input type text field and check value with if/else condition and give desire out through innerHTML to the target div #id.
Problem is I want to avoid all time to write "document.getElementById("showDay").innerHTML ". Is there a way to write simple code, which will perform same result?
working code - http://jsfiddle.net/animatorstar/5chokg76/4/
function checkDay()
{
var a = document.getElementById("enterNumber").value;
if (a==0) //condition
{
alert("value of a is "+a); //statements
document.getElementById("showDay").innerHTML = "Enter value between 1-7";
}
if (a==1) //condition
{
alert("value of a is "+a); //statements
document.getElementById("showDay").innerHTML = "Entered value is " + a + ", " + "Day is Monday";
}
else if (a==2) //condition
{
alert("value of a is "+a); //statements
document.getElementById("showDay").innerHTML = "Entered value is " + a + ", " + "Day is Tuesday";
}
else if (a==3) //condition
{
alert("value of a is "+a); //statements
document.getElementById("showDay").innerHTML = "Entered value is " + a + ", " + "Day is Wendesday";
}
else if (a==4) //condition
{
alert("value of a is "+a); //statements
document.getElementById("showDay").innerHTML = "Entered value is " + a + ", " + "Day is Thursday";
}
else if (a==5) //condition
{
alert("value of a is "+a); //statements
document.getElementById("showDay").innerHTML = "Entered value is " + a + ", " + "Day is Friday";
}
else if (a==6) //condition
{
alert("value of a is "+a); //statements
document.getElementById("showDay").innerHTML = "Entered value is " + a + ", " + "Day is Saturday";
}
else if (a==7) //condition
{
alert("value of a is "+a); //statements
document.getElementById("showDay").innerHTML = "Entered value is " + a + ", " + "Day is Sunday";
}
else
{
alert("Wrong value - Enter value between 1-7"); //statements
}
}
<input type="text" id="enterNumber" name="" placeholder="Enter number for check value" />
<button onClick="checkDay();"> Check Value </button>
<br>
<div id="showDay"> </div>