Jump to content
  • 0

Как запустить форму после нажатия на ENTER?


denis_alekss
 Share

Question

Как запустить форму при нажатии на клавишу ENTER? Не реагирует на ENTER, после ввода в текстовое поле.
 

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>Тег input, атрибут type</title>
  <script>
  function fanta(){
     if(one.elements.number.value == 5) alert("Все правильно!")
     document.getElementById('result').innerHTML = "Неправильно, введите в полее цифру 5"
  }
  </script>
 </head>
 <body>   
<form id="one">
   
    <input type="text" name="number">
    <input type="button"   value="Жми" onClick="fanta()">
</form>

<p id='result'></p>

 </body>
</html>

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Как вариант, замените 

<input type="button"   value="Жми" onClick="fanta()">

на

<input type="submit"   value="Жми" onClick="fanta(); return false;">

а еще не в функцию добавьте либо else либо return после выполнения условая.

 

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy