我创建了两个提交按钮,但是我希望这些功能一个接一个地运行。
单击提交按钮时,运行函数 validateBoxes 完成运行函数 validateBooking
我在下面粘贴了我的代码。新手非常感谢您的帮助。谢谢你。
<html>
<head>
<title>Jet2it Booking Service</title>
<script language="javascript" type="text/javascript">
function validateBoxes() {
var result = true;
var msg = "";
if (document.Holiday.firstname.value == "") {
msg += "You must enter your firstname \n";
document.Holiday.firstname.focus();
document.getElementById('firstname').style.color = "red";
result = false;
}
if (document.Holiday.secondname.value == "") {
msg += "You must enter your secondname \n";
document.Holiday.secondname.focus();
document.getElementById('secondname').style.color = "red";
result = false;
}
if (msg == "") {
return result;
}
{
alert(msg)
return result;
}
}
function validateBooking() {
var result = true;
var msg = "";
var booking = "";
if (Holiday.bookings[0].checked == true) {
booking = "Italy";
}
if (Holiday.bookings[1].checked == true) {
booking = "Malta";
}
if (Holiday.bookings[1].checked == true) {
booking = "Portugal";
}
if (confirm("You have selected " + booking + ". Continue?")) {
if (msg == "") {
return result;
}
{
alert(msg)
return result;
}
}
else {
alert("booking Error");
return false;
}
}
</script>
</head>
<body>
<form name="Holiday" method="post" action="confirmed.html">
<table width="50%" border="0">
<tr>
<td id="firstname">First firstname</td>
<td><input type="text" name="firstname" /></td>
</tr>
<tr>
<td id="secondname">Second name</td>
<td><input type="text" name="secondname" /></td>
</tr>
<tr>
<td><label>
<input type="radio" name="bookings" value="Italy"/>
Italy</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="bookings" value="Malta"/>
Malta</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="bookings" value="Portugal"/>
Portugal</label></td>
</tr>
<tr>
<td><input type="submit" name="Submit_firstname_etc"
value="Submit_firstname_etc" onClick="return validateBoxes();" /></td>
<td><input type="reset" name="Reset" value="Reset" /></td>
</tr>
<tr>
<td><input type="submit" name="Submit_Destination"
value="Submit_Destination" onClick="return validateBooking();" /></td>
<td><input type="reset" name="Reset" value="Reset" /></td>
</tr>
</table>
</form>
</body>
</html>