JavaScript - отключить кнопку отправки - PullRequest
0 голосов
/ 05 мая 2018

Моя функция не может отключить кнопку отправки (id = "mySubmit"), остальное работает нормально. (Функция вызывается по "onkeyup")

Я пытаюсь отключить его, если значения двух полей пароля не совпадают.

function check_match() {

    var pw1 = document.getElementById("one").value;
    var pw2 = document.getElementById("two").value;

    if (pw1 == pw2) {
        document.getElementById("error_match").style.color = "green";
        document.getElementById("error_match").innerHTML = "paswords match";
        document.getElementById("mySubmit").disabled = false;
    } else {
        document.getElementById("error_match").style.color = "red";
        document.getElementById("error_match").innerHTML = "passwords do not match";
        document.getElementById("mySubmit").disabled = true;
    }

}
<form action="#" class="userregister" method="POST">

    <label for="email"><b>E-Mail</b></label>
    <input type="email" placeholder="Enter E-Mail" name="email" required />

    <!--Password1-->
    <label for="password"><b>Passwort</b></label>
    <input type="password" placeholder="Enter Password" name="password" id="one" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" onkeyup="check_match();" required />
    <span id="error"></span>

    <!--Password2-->
    <label for="password2"><b>repeat Password</b></label>
    <input type="password" placeholder="Enter Password again" name="password2" id="two" onkeyup="check_match();" required />
    <span id="error_match"></span><br />

    <input type="checkbox" id="conditionbox" onclick="conditioncheck()" checked required>
    <a href="conditions.php" style="text-decoration: none">conditions </a>accepted<br />
    <span id="message" class="agberror"></span>

    <button type="submit" id="mySubmit" name="reg">Register</button>

</form>

Я помещаю часть скрипта в конец тега body

1 Ответ

0 голосов
/ 05 мая 2018

Вы просто используете === вместо ==.

3 == '3' // true - потому что значение одинаково 3 === '3' // false - тип данных не совпадает

всегда используйте === строго равен

...