I have this html page that is very simple: it has a text field and a submit button, what I want when you type something in the text field and press the function input button in the onclick event of the button being called. It works in IE and Google Chrome, but does not work in FireFox, is this normal behavior of FireFox or is there something missing here?
<html> <head> <script language="javascript"> function callMe() { alert("You entered: " + document.getElementById("txt").value); } </script> </head> <body> <input type="text" id="txt" /> <input type="submit" value="Submit" onclick="callMe()" /> </body> </html>
From the event descriptiononclick :
onclick
onclick . .
, UA , - .
, onsubmit :
onsubmit
onsubmit . FORM.
FORM
:
<html> <head> <script language="javascript"> function callMe() { alert("You entered: " + document.getElementById("txt").value); } </script> </head> <body> <form onsubmit="callMe()" action="#"> <input type="text" id="txt" /> <input type="submit" value="Submit" /> </form> </body> </html>
onsubmit - ( FF 3.5):
<html> <head> <script language="javascript"> function callMe() { alert("You entered: " + document.getElementById("txt").value); } </script> </head> <body> <form onsubmit="callMe()"> <input type="text" id="txt" /> <input type="submit" value="Submit" /> </form> </body> </html>
[edit .]
Chrome (4.0.223.11).
<input> s <form> - <form> , onclick ( , .
[edit HTML5]
, HTML5 click :
. , , , . (, , "enter", ), , , .
, ( ), " " ( click) , ( " " ). " " <form> parent form.
form
, , , , public-html, .
, "OnClick" "TextBox". TextBox.
If you enter text in a TextBox, left-click anywhere else on your page, and then press Enter, the OnClick event will work, oddly enough.
If you find a job, please let us know.
Source: https://habr.com/ru/post/1721380/More articles:Can I generate a file in javascript and request a user download? - javascriptWhat to do with third-party Javadoc - javaDoes Guice need a unit test? - unit-testingGeneric type in C #: limiting the type of a parameter as a collection - collectionsHow to create groups of related types for use in C # generics if there is no `typedef`? - c ++Why are there conflicts with git rebase -p -i? - gitGenerics and anonymous classes (bug or function?) - javaDynamic output update at the command line interface - cReturn random rows from the best (i.e. 100 rows → top 10 → get 5 random numbers) - sqlКак вернуть Nested PartialViews (включая их javascript) из вызова AJAX в ASP.Net MVC - asp.netAll Articles