<!DOCTYPE html>
<html>
<body>
<p>Type in the day of the week in the text box (numbers 1 to 7) and click 'search'</p>
<input type="text" id="dayInput" />
<button onclick="myFunction()">search</button>
<p id="demo"></p>
<script>
function myFunction()
{
var x;
var d = document.getElementById('dayInput).value;
switch (d)
{
case 0:
x="Lectures ... Sunday";
break;
case 1:
x="Lectures... Mon";
break;
case 2:
x="Lectures... Wed";
break;
case 3:
x="Lectures... Thu";
break;
case 4:
x="Lectures...Friday";
break;
case 5:
x="Lectures...Fri";
break;
case 6:
x="Lectures..Sat";
break;
}
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>
I type in a number in the search box (say 2) and the output is 'undefined'?
I don't understand why it's not giving me the case output.
I've tried to alter this code: http://www.w3schools...s/js_switch.asp
I can honestly say I've been stuck on this all day : / and just can't get it to work. Don't give me the code, just tell me what I'm doing wrong.
I've actually never done Javascript before (and yes this is a college assignment! A user enters a day of the week (number) and when he/she clicks search, we output the lectures we have on that particular day)
Thank you for your help.

New Topic/Question
Reply


MultiQuote





|