I cannot get the following code: when I press the enter key in the text box, the function is not called. I do not understand why, though ...
<form> <p align="center"> <input type="password" class="password" name="text1" onkeypress="submitonenter(text1.value,"money","cash",event)" /><br> <input type="button" value="Enter" style="width: 100px" name="Enter" onclick=javascript:validate(text1.value,"money","cash") /> </p> </form> <script type="text/javascript"> function submitonenter(text1,text2,text3,evt) { evt = (evt) ? evt : ((window.event) ? window.event : "") if (evt) { // process event here if ( evt.keyCode==13 || evt.which==13 ) { if (text1==text2) load('money/welcome.html'); else { if (text1==text3) load('cash/welcome.html'); else { load('failure.html'); } } } } } </script> <script language = "javascript"> function validate(text1,text2,text3) { if (text1==text2) load('money/welcome.html'); else { if (text1==text3) load('cash/welcome.html'); else { load('failure.html'); } } } function load(url) { location.href=url; } </script>
I'm not sure why you need the submitOnEnter function at all.
Why not just change the input type='button'to type='submit'and change the keyword onclickto onsubmit?
type='button'
type='submit'
onclick
onsubmit
EDIT: An apology, of course, 'onsubmit'should be put in the form tags, not the input. Providing the following:
'onsubmit'
<form onsubmit=validate(text1.value,"money","cash") > <p align="center"> <input type="password" class="password" name="text1" /><br> <input type="submit" value="Enter" style="width: 100px" name="Enter" /> </p> </form>
input type="submit" ( , Firefox):
<form id="myForm" method="POST" action="failure.html" onsubmit="return validate(document.getElementById('text1').value,'money','cash');"> <p align="center"> <input type="password" class="password" name="text1" id="text1"/><br> <input type="submit" value="Enter" style="width: 100px" name="Enter" /> </p> </form> <script language = "javascript"> function validate(text1,text2,text3) { var form=document.getElementById('myForm'); if (text1==text2) form.action='money/welcome.html'; else { if (text1==text3) form.action='cash/welcome.html'; else { form.action='failure.html'; } } return true; } </script>
: onSubmit, @mway ().
, - onclick, , onsubmit , / .
, , , "evt.preventDefault()", (.. ). , , location.href, , , .
, , , . . javascript ( ), . , . , , .:) , (, ). , , .
Source: https://habr.com/ru/post/1767182/More articles:How to implement an OpenID client from scratch? - openidИспользование JQuery getJSON с другими включенными JavaScripts дает ReferenceError - jsonDrupal: how to create a categorized menu tree - drupalAsp.net, where to store the username of the logged in user? - authenticationPHP repeating elements in a soap call - soapHow to redirect STDOUT and STDERR to a log file in Perl? - perlПрогресс UIProgressView не обновляется - iphoneIs it possible to extend a function call function in a PHP string? - stringHow can I start with Monte Carlo simulations for financial data in Perl? - algorithmCompress web pages with php, javascript, html and css in them - javascriptAll Articles