[英]javascript function not being called
我不知道为什么该函数不会调用。 最初,它来自带有onsubmit =“ return 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" />
为什么不运行?
确保关闭脚本标签和表单标签(如果仍然无法打开),请打开JavaScript控制台以查找任何语法错误
首先,将<script>
更改为<script type="text/javascript">
以使其更安全,并在js代码的末尾,确保放置结束脚本标记</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.