0

I have a simple jquery code here which includes a dialog with two text input fields, "nimi" and "tunnus". Within the dialog is also a "save" button, which is meant to check that the inputted values are 5 characters or longer, before allowing the dialog to close. The issue, however, is that nothing happens after "save" is clicked, aka the program never goes into either of the outcomes of the if() -statement. There is also a button within the dialog, "peruuta", which closes the dialog without making any checks, and it works flawlessly. Why is this, and how can I remedy it?

`

<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-3.6.1.min.js"></Script>
  <script src="https://code.jquery.com/ui/1.13.1/jquery-ui.min.js"></script>
</head>
<script>
  $(function(){
    $("#registerForm").dialog({
      autoOpen: false,
    });
    $("#register").click(function(){
      $("#registerForm").dialog("open");
    });
    $("#save").click(function(){
      
      if(document.getElementByID("nimi").value.length > 4 && document.getElementByID("tunnus").value.length > 4){
        $("#registerForm").dialog("close");
      }
      else{
        alert("Ei onnistunut");
      }
    });
    $("#peruuta").click(function(){
      $("#registerForm").dialog("close");
    });
  });
</script>
<body>
  <div id="registerForm" title="Rekisteröityminen">
    <p>Nimi:<input type="text" id="nimi"></p><br>
    <p>Tunnus:<input type="text" id="tunnus"></p><br>
    <input type="button" id="save" value="Save"></input><input type="button" id="peruuta" value="Peruuta"></input><br>
  </div>
  
  <input type="button" id="register" value="Rekisteröidy"></input>
</body>

`

I have tried putting the length of the inputs in separate variables and comparing those, which also didn't help. I additionally tinkered around with different comparators and ways to verify the input length in the if() -statement, but so far nothing works.

3
  • 1
    >> is the bitwise right shift operator. To check if a value is more than another value, use >. Commented Nov 27, 2022 at 17:48
  • @Ivar Yes sorry, that was a leftover from my comparator testing. I had it as simply ">" before, but that did not work either. Commented Nov 27, 2022 at 17:55
  • It should work if you correct al the typo's and invalid HTML. The <html> tag needs exactly one <head> and one <body> tag. You currently have a <script> between the head and the body, which is not allowed. <input> tags are "void" tags, and should not have an </input> end tag. getElementByID -> getElementById. Commented Nov 27, 2022 at 18:13

1 Answer 1

0

In addition to the comment by the @Ivar (>> should be >)

I believe that .getElementByID is misspelled it should be .getElementById (notice the lowercase 'd' at the end). You can see the error if you open the developer console.

Sign up to request clarification or add additional context in comments.

2 Comments

Wow, well that was it. I stared at this for hours with no idea what I was doing wrong, and it turned out to be one capitalized character that shouldn't be. Thank you for the help!
@NikoPuhakainen Always check the logs for errors. This should be in there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.