<
script
>
function validateData() {
//Basic check whether the username is filled or not.
if (document.Form.name.value == "") {
alert("Provide your name!");
document.Form.name.focus();
return false;
}
//checks whether the username is less than or
//equal to 8 characters or not
if (document.Form.name.value.length > 8) {
alert("Username should be utmost 8 characters!");
document.Form.name.focus();
return false;
}
//Checks whether the dropdown is selected or not.
if (document.Form.Galaxy.value == "-1") {
alert("Provide your Galaxy!");
return false;
}
//Checks whether the dropdown is selected or not.
if (document.Form.Guardian.value == "-1") {
alert("Provide your Favorite Guardian!");
return false;
}
}
</
script
>
<
center
>
<
h1
style
=
"color:green"
>Favorite Guardian Voting</
h1
>
<
form
action
=
"#"
name
=
"Form"
onsubmit
=
"return validateData()"
>
<
table
cellspacing
=
"0"
cellpadding
=
"3"
border
=
"1"
>
<
tr
>
<
td
align
=
"center"
>Username</
td
>
<
td
>
<
input
type
=
"text"
name
=
"name"
/>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"center"
>From Galaxy</
td
>
<
td
>
<
select
name
=
"Galaxy"
>
<
option
value
=
"-1"
selected>choose yours</
option
>
<
option
value
=
"1"
>Milky Way</
option
>
<
option
value
=
"2"
>Andromeda</
option
>
<
option
value
=
"3"
>Whirlpool</
option
>
</
select
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"center"
>Favorite Guardian</
td
>
<
td
>
<
select
name
=
"Guardian"
>
<
option
value
=
"-1"
selected>choose yours</
option
>
<
option
value
=
"1"
>Quill</
option
>
<
option
value
=
"2"
>Groot</
option
>
<
option
value
=
"3"
>Rocket</
option
>
<
option
value
=
"4"
>Drax</
option
>
<
option
value
=
"5"
>Gamora</
option
>
</
select
>
</
td
>
</
tr
>
<
tr
>
<
td
align
=
"right"
></
td
>
<
td
>
<
input
type
=
"submit"
value
=
"Submit"
/>
</
td
>
</
tr
>
</
table
>
</
form
>
</
center
>