我正在制作一个表单,询问三个不相关的问题,这些问题在单击提交按钮后显示文本。
所有三个问题都包含一个 if-else 语句;两个问题是文本输入,一个是选择框,然后是提交按钮。
我可以显示表单,但是当我输入数据并提交数据时,会返回一个空白表单而不是我想要的文本(我不是要显示“警报”消息)。
这是我到目前为止所拥有的:
<!DOCTYPE HTML>
<html>
<head>
<title>Questions</title>
<script type="text/javascript">
function questions()
{
var hours, age, timeday;
hours = document.form1.workhours.value;
hours = pasrseInt(hours);
age = document.form1.years.value;
age = parseInt(age);
timeday = document.form1.dayofweek.value;
}
if (hours >= 40)
{
document.write("Wow, what a hard worker!<br>");
}
else
{
document.write("Better work harder!<br>");
}
if ( age >= 65)
{
document.write("You are Eligible for retirement benefits<br>");
}
else
{
document.write("Sorry, no benefits yet.<br>");
}
if (day == "Sunday");
{
document.write("No need to pay the meter!<br>");
}
else
{
document.write("Better get some quarters!<br>");
}
</script>
</head>
<body>
<form name="form1">
How many hours have you worked? <input type="text" name="workhours"><br>
How old are you? <input type="text" name="years"><br>
What day is it today?
<select name="dayofweek">
<option value="???">-Select a Day-</option>
<option value="Sunday">Sunday</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
</select></br>
<p>
</p>
<input type="submit" value="Submit" onClick="questions()">
</form>
</body>
</html>