I'm trying to get my code to alert me if anything is not filled in, checked, or selected before it submits. I'm also having trouble getting it to alert me if a month or day isn't selected. Any insight or assistance would be greatly appreciated!
<html>
<head>
<title>Field Trip Consent Form</title>
<script type="text/javascript">
function validates() {
var radioChecked = false;
for(var i=0; i< document.form1.permission.length; i++) {
if(document.form1.permission[i].checked) {
radioChecked = true;
}
}
if(radioChecked == false) {
alert("Please chose permission Status");
return false;
}
if(document.form1.txtParent.value == "") {
alert("Please type in the textbox");
return false;
}
if(document.form1.destination.value == "") {
alert("Please type in the textbox");
return false;
}
return true;
}
function validates1(){
var moMonth = document.getElementById("getMonth").value;
var moDay = document.getElementById("day").value;
if(moMonth == "") {
alert("Please select a Month");
return false;
}
if(moDay == "") {
alert("Please select a Day");
return false;
}
return true;
}
</script>
</head>
<body>
<h1>Field Trip Consent Form</h1>
<form name="form1" onsubmit="return validates(); validates1()" method="post"
action="http://ift.tt/1DwGz8y">
<form>
<h2>Description of Trip</h2>
<p>Destination
<input type="text" name="destination" SIZE="50" /></p>
<p>Date of Trip
<select name="month" id='getMonth'>
<option selected value="Month">Month
<option value="Jan">Jan
<option value="Feb">Feb
<option value="Mar">Mar
<option value="Apr">Apr
<option value="May">May
<option value="Jun">Jun
<option value="Jul">Jul
<option value="Aug">Aug
<option value="Sep">Sep
<option value="Oct">Oct
<option value="Nov">Nov
<option value="Dec">Dec
</select>
<select name="day">
<option selected value="Day">Day
<option value="01">01
<option value="02">02
<option value="03">03
<option value="04">04
<option value="05">05
<option value="06">06
<option value="07">07
<option value="08">08
<option value="09">09
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31
</select>
<select name="year">
<option selected value="2012">2012
<option value="2013">2013
<option value="2014">2014
<option value="2015">2015
</select>
<h2>Parental Information</h2>
<p>Mother's Name
<input type="text" name="txtParent" size="20" /></p>
<p>Mother's Work Phone
<input type="text" name="txtParent" size="20" /></p>
<p>Father's Name
<input type="text" name="txtParent" size="20" /></p>
<p>Father's Work Phone
<input type="text" name="txtParent" size="20" /></p>
<p><input type="radio" name="permission" value="yes" /> Permission is Granted
<input type="radio" name="permission" value="no" /> Permission is NOT Granted </p>
<p><input type="submit" value="Submit This Data" />
<input type="reset" /></p>
</form>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire