Home  >  Q&A  >  body text

I want this condition to fill in the input of the validation form

const userinfo = () => {
  // Trim -- remove spaces
  username = document.getElementById("username").value.trim();
  email = document.getElementById("email").value.trim();
  password = document.getElementById("password").value.trim();
  confirmpassword = document.getElementById("confirmpassword").value.trim();
  console.log(username, email, password, confirmpassword);
};
const checkinput = () => {
  // Not Null
  if (
    username.trim().length !== 0 &&
    email.trim().length !== 0 &&
    password.trim().length !== 0 &&
    confirmpassword.trim().length !== 0
  ) {
    return true;
  } else {
    // Style Java
    // Element.style.typeof style(Border, Size, Font, Color)
    msgPassword.style.border = "2px solid red";
    msgConfirm.style.border = "2px solid red";
    document.getElementById("error-allength").innerHTML =
      "place fill all filed ";
    return false;
  }
};

I want this condition to be used to fill in the input of the validation form, I think this is an impossible problem to solve, please help me!

P粉908643611P粉908643611403 days ago469

reply all(1)I'll reply

  • P粉738248522

    P粉7382485222023-09-12 16:01:27

    const checkinput = () => {
      if (
        username.trim().length !== 0 ||
        email.trim().length !== 0 ||
        password.trim().length !== 0 ||
        confirmpassword.trim().length !== 0
      ) {
        return true;
      } else {
        
        msgPassword.style.border = "2px solid red";
        msgConfirm.style.border = "2px solid red";
        document.getElementById("error-allength").innerHTML =
          "请填写所有字段";
        return false;
      }
    };

    reply
    0
  • Cancelreply