admin管理员组文章数量:1316388
I have JavaScript code including several functions, the main one being CheckForm()
.
The function is called by clicking the 'Submit' button:
<td><input type="submit" name="submit1" id="submit1" value="Register" onclick="return CheckForm();"/></td>
But when the button is pressed nothing happens (the function isn't performed). What can I do to fix this?
I have JavaScript code including several functions, the main one being CheckForm()
.
The function is called by clicking the 'Submit' button:
<td><input type="submit" name="submit1" id="submit1" value="Register" onclick="return CheckForm();"/></td>
But when the button is pressed nothing happens (the function isn't performed). What can I do to fix this?
Share Improve this question edited Apr 12, 2022 at 15:57 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Apr 2, 2013 at 10:42 user2235692user2235692 2712 gold badges3 silver badges5 bronze badges 4- 7 Post the code for the function – Jeff Shaver Commented Apr 2, 2013 at 10:44
- 2 put a console.log / or alert in the top of the function so you know if it gets fired at all – Matthias Wegtun Commented Apr 2, 2013 at 10:47
- 1 Anything in the error console in firebug? – topcat3 Commented Apr 2, 2013 at 10:47
- Can you write the skeleton of checkForm code? Can you check the browser log to see if there is any error in the page? – Peter Tadros Commented Apr 2, 2013 at 10:48
2 Answers
Reset to default 2Have you tried debugging your code using FireBug or jsFiddle?
Some possible causes are an incorrectly named function or function call(remember that JavaScript is case sensitive), an error in your function or your JavaScript code not being referenced in your page.
If you aren't using either of the above tools then try using a console.log or alert inside your function to see if it is being called.
You can use it like this.
function CheckForm()
{
//doing stuff
return true;
}
<form id="formToCheck"></form>
$('#formToCheck').submit(CheckForm);
Hope it helps
if you want to do it without jquery just add on
<form onSubmit="return CheckForm()"></form>
You can read more about form validation without jQuery here -> http://www.w3schools./js/js_form_validation.asp#gsc.tab=0
Maybe if it doesn't work you have some errors. Check JS console in your browser and remove them.
本文标签: htmlJavaScript onclick() function not workingStack Overflow
版权声明:本文标题:html - JavaScript onclick() function not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742002090a2411219.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论