我試圖讓我的代碼提醒我,如果在提交之前沒有填寫,選中或選擇任何內容。如果沒有選擇一個月或一天,我也很難提醒我。任何見解或協助將不勝感激!JavaScript表單提交幫助
<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://legacy.jefferson.kctcs.edu/users/mark.prather/formhandler.asp">
<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>
我被困在從我的第一功能的迴路。即使將數據輸入到表單中,它也會提醒我我沒有。 – 2015-04-03 23:08:07