Pressing input inside a text field does not fire onclick event of submit button in firefox

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>
+3
source share
4 answers

From the event descriptiononclick :

onclick . .

, UA , - .

, onsubmit :

onsubmit . 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>
+9

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>
+1

[edit .]

Chrome (4.0.223.11).

<input> s <form> - <form> , onclick ( , .

[edit HTML5]

, HTML5 click :

. , , , . (, , "enter", ), , , .

, ( ), " " ( click) , ( " " ). " " <form> parent form.

, , , , public-html, .

0

, "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.

0
source

Source: https://habr.com/ru/post/1721380/


All Articles