Q:

i am trying to disable a button in my html form but i dont know what went wrong can some one help me

I am creating a password change page.  I am trying to disable the submit button when the two passwords do not match.  I don't know what went wrong can some one explain to me? 
<form role="form">
    <div class="form-group">
        <label>Existing Password</label>
        <input class="form-control" name="password" type="password" placeholder="Existing Password" required/>
    </div>
    <div class="form-group">
        <label>New Password</label>
        <input class="form-control" name="npassword" type="password" placeholder="New Password" id="npassword" onchange='check_pass();' required/>
    </div>
    <div class="form-group">
        <label>Confirm New Password</label>
        <input class="form-control" name="cnpassword" type="password" placeholder="Confirm New Password" id="cnpassword " onchange='check_pass();' required/>
    </div>
    <button name="submit" type="submit" class="btn btn-default" id="submit" disabled>Submit </button>
    <button type="reset" class="btn btn-default">Reset Button</button>
    <script>
        function check_pass() {
            if (document.getElementById('npassword').value == document.getElementById('cnpassword').value) {
                document.getElementById('submit').disabled = false;
            } else {
                document.getElementById('submit').disabled = true;
            }
        }
    </script>
</form>

A:

You have a space in cnpassword's id.

<form role="form">
  <div class="form-group">
    <label>Existing Password</label>
    <input class="form-control" name="password" type="password" placeholder="Existing Password" required/>
  </div>
  <div class="form-group">
    <label>New Password</label>
    <input class="form-control" name="npassword" type="password" placeholder="New Password" id="npassword" onchange='check_pass();' required/>
  </div>
  <div class="form-group">
    <label>Confirm New Password</label>
    <input class="form-control" name="cnpassword" type="password" placeholder="Confirm New Password" id="cnpassword" onchange='check_pass();' required/>
  </div>
  <button name="submit" type="submit" class="btn btn-default" id="submit" disabled>Submit </button>
  <button type="reset" class="btn btn-default">Reset Button</button>
  <script>
    function check_pass() {
      if (document.getElementById('npassword').value == document.getElementById('cnpassword').value) {
        document.getElementById('submit').disabled = false;
      } else {
        document.getElementById('submit').disabled = true;
      }
    }
  </script>

