I am trying to make a sample webpage that asks users for an integer, and if it is between 1 and 12, it will return the corresponding day of christmas (8th day of christmas: 8 maids a milking, etc.)
I am not very experienced with javascript, but I am not aware of any other way to make the program work in html. Python is not an option, sadly. I am stuck while trying to gather a user-provided integer as a variable which the webpage then displays. My code is below. Any help or suggestions are greatly appreciated.
<!>
<html>
<head>
<title> Merry Christmas! </title>
</head>
<body>
<input type="number" id="inputfield1" name="inputfield1" />
<input type="submit" id="Submit" text="Submit" onclick="compute()" />
<script type = "text/javascript">
function compute(){
var cday = document.getElementByName("inputfield1");
document.write(cday);
}
</script>
</body>
</html>
var cday = document.getElementByName("inputfield1").value;.valueproperty to get what the user typed. Stick a+just before it (ie. beforedocument.) to convert it to a number. You need an array of values, and just get the corresponding one. Easy, right?