admin管理员组文章数量:1317910
I would like to add some inline javascript that alerts the user with a message AND then returns false, preventing the form from submitting.
onsubmit="return alert('You must be logged in to register'); return false"
With the code above, I get the alert but the form still submits. I would like to retain the inline JS if possible. I searched around but couldn't find an inline example that follows this pattern. I know how to achieve this by executing a function with onsubmit, but again, would like to retain inline if possible.
I would like to add some inline javascript that alerts the user with a message AND then returns false, preventing the form from submitting.
onsubmit="return alert('You must be logged in to register'); return false"
With the code above, I get the alert but the form still submits. I would like to retain the inline JS if possible. I searched around but couldn't find an inline example that follows this pattern. I know how to achieve this by executing a function with onsubmit, but again, would like to retain inline if possible.
Share Improve this question asked Jul 11, 2014 at 17:45 cpcdevcpcdev 1,2223 gold badges20 silver badges52 bronze badges 1-
1
Why are you using
return alert()
and notalert()
? Right now, you are returning two values, meaning that the second one won't ever get returned. – Max Commented Jul 11, 2014 at 17:47
3 Answers
Reset to default 2Try this :
<form onsubmit=" alert('You must be logged in to register');return false;"><input type="submit" /></form>
"Return" stops the stack instruction.
You can not return twice from one function. Get rid of first return and it'll work as charm
by jquery you can do this:
$("#inputID").submit(function(e){
e.preventDefault();
...do whatever you want...
});
本文标签: javascriptonSubmit Alert and Return False using inline JSStack Overflow
版权声明:本文标题:javascript - onSubmit Alert and Return False using inline JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742029140a2416112.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论