1

The JavaScript function does not apply to the form and the Submit button in HTML The 'js' file is inside another folder I also did the link to the 'js' file correctly

function check_pass() {
  if (document.getElementById('password').value == document.getElementById('passwordconfirm').value) {
      document.getElementById('submit').disabled = false;
  } else {
      document.getElementById('submit').disabled = true;
  }
}
<form name="cForm" id="cForm" method="post" action="php/save.php">
  <fieldset>
      <div class="form-field">
          <input name="username" type="text" id="username" class="full-width" placeholder="نام کاربری" value="">
      </div>
      <div class="form-field">
          <input name="email" type="email" id="email" class="full-width" placeholder="ایمیل" value="">
      </div>
      <div class="form-field">
         <input name="password" type="password" id="password" class="full-width" placeholder="پسوورد" value="" onkeyup="check_pass();">
      </div>
      <div class="form-field">
          <input name="passwordconfirm" type="password" id="passwordconfirm" class="full-width" placeholder="تکرار پسوورد" value="" onkeyup="check_pass();">
      </div>
      <button type="submit" id="submit" class="submit button-primary full-width-on-mobile" disabled>ثبت</button>
  </fieldset>
</form>
Aᴍɪʀ
  • 7,623
  • 3
  • 38
  • 52
  • You're only calling `check_pass()` for the `keyup` event on your password fields. Your submit button doesn't know about that function. – mykaf Jun 06 '22 at 16:57
  • Add `document.getElementById("cForm").addEventListener("submit", check_pass);` to your javascript code. – bloodyKnuckles Jun 06 '22 at 17:18

0 Answers0