What's the mistake?



  • <html>
    <text javascript="">
    <script>
        var val = $("input[name=name_of_input]").val();
        if (val == 1) document.location.href = '65.html';
        else if (val == 2) document.location.href = '43.html';
        else alert("Данный код в баззе не храниться!");
    </script>
    </html>
    

    Help me, please.



  • No one knows exactly what you wanted out there, but my crystal ball tells me you want to open another page at the meaning of the text field or to swear to the user.

    Let's assume that you want this to happen by pressing Enter's keyboard after entering the field:

    <html>
    <head>
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
      <script lang="javascript">
        function onKeyPress(event) {
          if (event.keyCode == 13) {
            val = $("input[name=name_of_input]").val();
            if (val == 1) document.location.href = '65.html';
            else if (val == 2) document.location.href = '43.html';
            else alert("Данный код в базе не хранится!");
          }
        }
      </script>
    </head>
    <body>
      <input type="text" name="name_of_input" onKeyPress="onKeyPress(event)"/>
    </body>
    </html>
    

    UPD1. The button version.

    <html>
    <head>
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
      <script lang="javascript">
        function onClick() {
            val = $("input[name=name_of_input]").val();
            if (val == 1) document.location.href = '65.html';
            else if (val == 2) document.location.href = '43.html';
            else alert("Данный код в базе не хранится!");
        }
      </script>
    </head>
    <body>
      <input type="text" name="name_of_input" />
      <input type="button" value="Проверить" onClick="onClick()"/>
    </body>
    </html>
    

    Don't be embarrassed to experiment, rule the code and see what happens.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2