我不知道为什么这个功能不会打电话。最初是来自onsubmit ="返回checkFilled()"但我也试过用一个onclick事件用一个按钮调用它,它永远不会进入该功能。这是代码:
function checkFilled() {
alert("Entered"); //just to test if entering function
return false;
var currentBox = document.getElementById("livCost").value;
if (currentBox == null) {
alert("Not all preferences are filled out!");
return false;
}
currentBox = document.getElementById("travOps").value;
else if (currentBox == "Select") {
alert("Not all preferences are filled out!");
return false;
} else
return true;
}

<form onsubmit="return checkFilled()" method="post" action="recommendScript.php">
<p>Cheap living cost :
<select name="livingCost" id="livCost">
<option selected>Select</option>
<option value="1">1</option>
<option value="2">2</option>
<p>Travel Opportunities :
<select name="travelOps" id="travOps">
<option selected>Select</option>
<option value="1">1</option>
<option value="2">2</option>
</select></p>
<input type="submit" value="Submit" class="loginButton" />
&#13;
为什么不参加此活动?
答案 0 :(得分:0)
确保关闭脚本标记和表单标记,如果仍然无法打开javascript控制台以查找任何语法错误
答案 1 :(得分:-5)
首先,将<script>
更改为<script type="text/javascript">
以使其更安全,并在js代码的最后,确保放置结束脚本标记</script>