Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a html form that asks the user for their age and whether they are registe

ID: 668143 • Letter: C

Question

create a html form that asks the user for their age and whether they are registered to vote. You will then indicate whether or not they are eligible to vote.

1.Ask the user for their age (in a textbox). Be sure to use use the parseInt()function to convert the text field to an integer.

2.Have a select box asking them if they have registered to vote with options for ‘Yes’ and ‘No’.

3.If they are 18 or over, AND they selected the option that said they are registered, then output that they are eligible. Otherwise, output that they are not eligible. Use an alert() box to output the message.

Explanation / Answer

<!DOCTYPE html>
<html>
<head>
<script>
function validateForm()
{
var x=document.forms["myForm"] ["Age"].value;

var y =document.forms["myForm"] ["Vote"].value;
if(x== null || x== "" )
{
alert("Age must be filled out");

}
else if( x>=18 && y=="Yes")
{
alert("They are eligible");
}
else
{
alert("They are not eligible");
}
}
</script>
</head>

<body>

<form name="myForm" method="post">
Age <input type="textbox" name="Age">
<br>
Registered for Vote? <select name="Vote">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<br><br>
<input type="submit" value="submit">
</form>
</body>
</html>