我的第二页有两个单选按钮,确定是否VoIP或带宽和电子邮件的文本字段。当我转到第三页时,我看到URL中的值如预期的那样。但是,当我提交一个持续时间时,我只在URL中得到持续时间,而不是电子邮件或testType。
我还有5个页面,我想让参数建立起来。
html:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<form id="myForm" onsubmit="goPFour(event)" method="get">
<div id="pBFContainer" class="container">
<div id="bodyFOption1">
<label for="testTime">How long would you like the VoIP test to run?<p></label>
<input type="radio" class="testD" name="testTime" value="10" checked/>10 Seconds
<input type="radio" class="testD" name="testTime" value="20" />20 Seconds
</div>
</div>
<input type="submit" id="subButton" value="Next..." />
</form>
</body>
<script type="text/javascript" src="evalportalp1.js"></script>
</html>
JS:
function goPFour(event) {
event.preventDefault();
const formData = new FormData(event.target);
const userEmail = formData.get("email");
const testType = formData.get("testType");
const testTime = formData.get("testTime")
if (testTime === "10") {
//console.log("testTime is 10");
window.location.href = "evalportalv4.html?" + "email=" + userEmail + "&testType=" + testType + "&testTime=" + testTime;
} else if (testTime === "20") {
//console.log("testTime is 20");
window.location.href = "evalportalv4.html?" + "email=" + userEmail + "&testType=" + testType + "&testTime=" + testTime;
} else {
alert("Please pick a valid Option");
}
return false;
}
function goPThree(event) {
event.preventDefault();
const formData = new FormData(event.target);
const userEmail = formData.get("email");
const testType = formData.get("testType");
if (testType === "voip") {
//console.log("testtype is voip");
window.location.href = "evalportalv3.html?" + "email=" + userEmail + "&testType=" + testType;
} else if (testType === "bandwidth") {
//console.log("testtype is bandwidth");
window.location.href = "evalportalb3.html?" + "email=" + userEmail + "&testType=" + testType;
} else {
alert("Please pick a valid Option");
}
return false;
}
可能是因为你的两个单选按钮有相同的名称"testTime" ?或者没有"testType">
你觉得怎么样?