3
Hi, I’m starting programming in jQuery. I’ve moved a little but I don’t know that much. I am making a simple code for checking blank fields in inputs from a login screen.
This is the code:
$("#enter").on("click", function () {
        if ($("#numeroSerie").val().trim() == "") {
            $("#numeroSerie").val("");
        }
        if ($("#user").val().trim() == "") {
            $("#user").val("");
        }
        if ($("#pass").val().trim() == "") {
            $("#pass").val("");
        }
    });
Dice:
-enter is the login Submit button
-numeroSerie, user and pass are the inputs.
The code is working ok, but I feel like I’m spending a lot of code for this, I know there’s a simplified way, someone there could give me a moral to learn how to do it in a better and more organized way?
I’ll leave a simple example of code there:
$(document).ready(function () {
  $("#enter").on("click", function () {
      if ($("#numeroSerie").val().trim() == "") {
          $("#numeroSerie").val("");
      }
      if ($("#user").val().trim() == "") {
          $("#user").val("");
      }
      if ($("#pass").val().trim() == "") {
          $("#pass").val("");
      }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form method="POST">
Número de série: <input type="text" id="numeroSerie" required><br>
<br>Usuário: <input type="text" id="user" required><br>
<br>Senha: <input type="password" id="pass" required><br>
<br><input type="submit" id="enter">
</form>
Well, simply put, I’d just like to join the verification of those three in one.
Thank you guys.
Thank you very much man, it worked perfectly!
– user149429