Остановка отправляет с пустыми входными значениями

GC .Net очень ... ленивый. Тот факт, что упоминание было утеряно, не означает, что он сразу же выметается, разбивается и отправляется на свалку. По этой причине всегда полезно закрывать открытые ресурсы и удалять объекты, которые реализуют IDisposable.

6
задан Brad Birdsall 25 July 2009 в 18:55
поделиться

2 ответа

Пример кода с фиктивными проверками:

<script type="text/javascript">
function checkForm(form) {
    var mailCheck = checkMail(form.elements['email']),
        pwdCheck = checkPwd(form.elements['pwd']);
    return mailCheck && pwdCheck;
}

function checkMail(input) {
    var check = input.value.indexOf('@') >= 0;
    input.style.borderColor = check ? 'black' : 'red';
    return check;
}

function checkPwd(input) {
    var check = input.value.length >= 5;
    input.style.borderColor = check ? 'black' : 'red';
    return check;
}
</script>

<style type="text/css">
#login input {
    border: 2px solid black;
}
</style>

<form id="login" method="post" action="" onsubmit="return checkForm(this)"> 
    <input type="text" name="email" id="email" onkeyup="checkMail(this)"/> 
    <input type="password" name="pwd" id="pwd" onkeyup="checkPwd(this)"/> 
    <button type="submit" id="submit">Login</button>
</form>
9
ответ дан 8 December 2019 в 17:25
поделиться

Possible approach:

  • setting action to #
  • adding handler to the submit button or the onsubmit of the form
  • change the action of the form, if text fields are not empty

Edit: To make this even work for non-javascript users insert the #-action when page is loaded.

3
ответ дан 8 December 2019 в 17:25
поделиться
Другие вопросы по тегам:

Похожие вопросы: