简体   繁体   中英

javascript function not being called

I have no idea why the function won't call. Initially it was from the form with onsubmit="return checkFilled()" but I also tried just calling it with an onclick event in with a button and it never enters the function. Here is the code:

 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" /> 

Why won't this run?

确保关闭脚本标签和表单标签(如果仍然无法打开),请打开JavaScript控制台以查找任何语法错误

首先,将<script>更改为<script type="text/javascript">以使其更安全,并在js代码的末尾,确保放置结束脚本标记</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM