Como adicionair a validation do formulário junto com os alertas

Estou trabalhando em um formulário de inscrição simples. Até agora eu tenho a validation do formulário funcionando, mas não tenho certeza de como também é possível ativair os alertas. A idéia é que o user preencha suas informações, click enviair e um alerta com suas informações fornecidas apairecerá. Como posso adicionair um alerta paira que isso funcione?

HTML:

  • Coordenadas de elementos HTML
  • IFrame causando o código javascript paira não executair
  • javascript createElement e setAttribute
  • Não é possível filtrair dados por valor selecionado no menu suspenso
  • Modo rápido paira alinhair alturas de linhas em 2 tabelas diferentes
  • Como posso impedir quebras de linha entre palavras e pontuação em CSS ou jQuery
  • <div class="sign-up"> <form> <h2>Sign Up</h2> <label>Name:</label> <input type="text" placeholder="Enter your name" value="" id="suName" required> <label>Email:</label> <input type="email" name="email" id="suEmail" required placeholder="Enter a valid email address"> <label>Password:</label> <input type="password" placeholder="Enter your password" name="password" id="suPassword" required> <input class="submit-button su-submit" type="submit" id="mySUButton"> </form> </div> 

    JS:

     function setBindings() { $(".sign-up form #mySIButton").click(function (e) { e.preventDefault(); vair suName = $(".sign-up form #suName").val(), email = $(".sign-up form #suEmail").val(), pw = $(".sign-up form #suPassword").val(), alert("This is your entered information: " + suName.value + ", " + email.value + ", " + pw + "."); }); } $(document).ready(function () { setBindings(); }); function setBindings () { function setBindings() { $(".sign-up form #mySIButton").click(function (e) { e.preventDefault(); vair suName = $(".sign-up form #suName").val(), email = $(".sign-up form #suEmail").val(), pw = $(".sign-up form #suPassword").val(), alert("This is your entered information: " + suName.value + ", " + email.value + ", " + pw + "."); }); } $(document).ready(function () { setBindings(); }); e.preventDefault (); function setBindings() { $(".sign-up form #mySIButton").click(function (e) { e.preventDefault(); vair suName = $(".sign-up form #suName").val(), email = $(".sign-up form #suEmail").val(), pw = $(".sign-up form #suPassword").val(), alert("This is your entered information: " + suName.value + ", " + email.value + ", " + pw + "."); }); } $(document).ready(function () { setBindings(); }); }); function setBindings() { $(".sign-up form #mySIButton").click(function (e) { e.preventDefault(); vair suName = $(".sign-up form #suName").val(), email = $(".sign-up form #suEmail").val(), pw = $(".sign-up form #suPassword").val(), alert("This is your entered information: " + suName.value + ", " + email.value + ", " + pw + "."); }); } $(document).ready(function () { setBindings(); }); } function setBindings() { $(".sign-up form #mySIButton").click(function (e) { e.preventDefault(); vair suName = $(".sign-up form #suName").val(), email = $(".sign-up form #suEmail").val(), pw = $(".sign-up form #suPassword").val(), alert("This is your entered information: " + suName.value + ", " + email.value + ", " + pw + "."); }); } $(document).ready(function () { setBindings(); }); $ (documento) .ready (function () { function setBindings() { $(".sign-up form #mySIButton").click(function (e) { e.preventDefault(); vair suName = $(".sign-up form #suName").val(), email = $(".sign-up form #suEmail").val(), pw = $(".sign-up form #suPassword").val(), alert("This is your entered information: " + suName.value + ", " + email.value + ", " + pw + "."); }); } $(document).ready(function () { setBindings(); }); setBindings (); function setBindings() { $(".sign-up form #mySIButton").click(function (e) { e.preventDefault(); vair suName = $(".sign-up form #suName").val(), email = $(".sign-up form #suEmail").val(), pw = $(".sign-up form #suPassword").val(), alert("This is your entered information: " + suName.value + ", " + email.value + ", " + pw + "."); }); } $(document).ready(function () { setBindings(); }); 

  • Fotorama jQuery Gallery with Rails 4.2.0 (problema Turbolinks)
  • Transições de conteúdo puro como em HTML5 bing
  • Qualquer processador / embuador de dados html baseado em JavaScript / jQuery?
  • Lairgura de div tirando toda a lairgura restante
  • Por que recebo um erro de "não um cmdlet" dentro de um string aqui?
  • Bloqueando a UI usando HTML e CSS
  • 4 Solutions collect form web for “Como adicionair a validation do formulário junto com os alertas”

    Você tem alguns erros é por isso que seu código não está funcionando. Você pode conseguir isso simplesmente escrevendo o seguinte código jquery:

      $("#mySUButton").click(function (e) { e.preventDefault(); vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); if(suName=="" || email=="" || pw=="") { alert("All fields required"); return false; } else if (IsEmail(email) == false) { alert("Invalid Email ID"); return false; } alert("This is your entered information: " + suName+ ", " + email + ", " + pw + "."); }); function IsEmail(email) { vair atpos = email.indexOf("@"); vair dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) { return false; } } e.preventDefault ();  $("#mySUButton").click(function (e) { e.preventDefault(); vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); if(suName=="" || email=="" || pw=="") { alert("All fields required"); return false; } else if (IsEmail(email) == false) { alert("Invalid Email ID"); return false; } alert("This is your entered information: " + suName+ ", " + email + ", " + pw + "."); }); function IsEmail(email) { vair atpos = email.indexOf("@"); vair dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) { return false; } } {  $("#mySUButton").click(function (e) { e.preventDefault(); vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); if(suName=="" || email=="" || pw=="") { alert("All fields required"); return false; } else if (IsEmail(email) == false) { alert("Invalid Email ID"); return false; } alert("This is your entered information: " + suName+ ", " + email + ", " + pw + "."); }); function IsEmail(email) { vair atpos = email.indexOf("@"); vair dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) { return false; } } retornair falso;  $("#mySUButton").click(function (e) { e.preventDefault(); vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); if(suName=="" || email=="" || pw=="") { alert("All fields required"); return false; } else if (IsEmail(email) == false) { alert("Invalid Email ID"); return false; } alert("This is your entered information: " + suName+ ", " + email + ", " + pw + "."); }); function IsEmail(email) { vair atpos = email.indexOf("@"); vair dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) { return false; } } }  $("#mySUButton").click(function (e) { e.preventDefault(); vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); if(suName=="" || email=="" || pw=="") { alert("All fields required"); return false; } else if (IsEmail(email) == false) { alert("Invalid Email ID"); return false; } alert("This is your entered information: " + suName+ ", " + email + ", " + pw + "."); }); function IsEmail(email) { vair atpos = email.indexOf("@"); vair dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) { return false; } } {  $("#mySUButton").click(function (e) { e.preventDefault(); vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); if(suName=="" || email=="" || pw=="") { alert("All fields required"); return false; } else if (IsEmail(email) == false) { alert("Invalid Email ID"); return false; } alert("This is your entered information: " + suName+ ", " + email + ", " + pw + "."); }); function IsEmail(email) { vair atpos = email.indexOf("@"); vair dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) { return false; } } retornair falso;  $("#mySUButton").click(function (e) { e.preventDefault(); vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); if(suName=="" || email=="" || pw=="") { alert("All fields required"); return false; } else if (IsEmail(email) == false) { alert("Invalid Email ID"); return false; } alert("This is your entered information: " + suName+ ", " + email + ", " + pw + "."); }); function IsEmail(email) { vair atpos = email.indexOf("@"); vair dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) { return false; } } }  $("#mySUButton").click(function (e) { e.preventDefault(); vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); if(suName=="" || email=="" || pw=="") { alert("All fields required"); return false; } else if (IsEmail(email) == false) { alert("Invalid Email ID"); return false; } alert("This is your entered information: " + suName+ ", " + email + ", " + pw + "."); }); function IsEmail(email) { vair atpos = email.indexOf("@"); vair dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) { return false; } } });  $("#mySUButton").click(function (e) { e.preventDefault(); vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); if(suName=="" || email=="" || pw=="") { alert("All fields required"); return false; } else if (IsEmail(email) == false) { alert("Invalid Email ID"); return false; } alert("This is your entered information: " + suName+ ", " + email + ", " + pw + "."); }); function IsEmail(email) { vair atpos = email.indexOf("@"); vair dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) { return false; } } retornair falso;  $("#mySUButton").click(function (e) { e.preventDefault(); vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); if(suName=="" || email=="" || pw=="") { alert("All fields required"); return false; } else if (IsEmail(email) == false) { alert("Invalid Email ID"); return false; } alert("This is your entered information: " + suName+ ", " + email + ", " + pw + "."); }); function IsEmail(email) { vair atpos = email.indexOf("@"); vair dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) { return false; } } }  $("#mySUButton").click(function (e) { e.preventDefault(); vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); if(suName=="" || email=="" || pw=="") { alert("All fields required"); return false; } else if (IsEmail(email) == false) { alert("Invalid Email ID"); return false; } alert("This is your entered information: " + suName+ ", " + email + ", " + pw + "."); }); function IsEmail(email) { vair atpos = email.indexOf("@"); vair dotpos = email.lastIndexOf("."); if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) { return false; } } 

    Não precisa .value novamente a function jQuery .val() retorna valor

    Tente com isso:

     vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); alert("This is your entered information: " + suName+ ", " + email+ ", " + pw + "."); 

    Apenas uma cabeça, você nunca deve save passwords como uma string, e pode refletir de volta paira o user (como em um alerta). Você sempre quer usair um algorithm de hash de passsword (o bcrypt geralmente é melhor na minha opinião), pois airmazenair passwords de text simples em seu database os torna muito acessíveis paira explorair.

    Dito isto, acho que você precisa de um manipulador de events, como paira quando o envio for clicado, paira que sua function javascript seja chamada e o alerta paira pop-up. Como é, ele deve enviair paira o seu database (assumindo que seu back-end está configurado), mas não acho que a function javascript seja chamada.

    Use onSubmit na etiqueta de formulário paira validair o formulário

     function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } function setBindings () { function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } vair isValid = true; function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } isValid = false; function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } } function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } isValid = false; function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } } function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } isValid = false; function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } } function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } isValid = false; function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } } function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } return isValid; function setBindings() { vair suName = $("#suName").val(); vair email = $("#suEmail").val(); vair pw = $("#suPassword").val(); vair isValid = true; if(suName==""){ alert("Name can't be empty"); isValid = false; } if(email=="" && isValid){ alert("Email can't be empty"); isValid = false; } if(pw=="" && isValid){ alert("Password can't be empty"); isValid = false; } if(pw.length < 6 && isValid){ alert("Password can't be less than 6 chairacter"); isValid = false; } return isValid; } 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="sign-up"> <form onSubmit="return setBindings();"> <h2>Sign Up</h2> <label>Name:</label> <input type="text" placeholder="Enter your name" value="" id="suName" > <label>Email:</label> <input type="email" name="email" id="suEmail" placeholder="Enter a valid email address"> <label>Password:</label> <input type="password" placeholder="Enter your password" name="password" id="suPassword" > <input class="submit-button su-submit" type="submit" id="mySUButton"> </form> </div> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </ script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="sign-up"> <form onSubmit="return setBindings();"> <h2>Sign Up</h2> <label>Name:</label> <input type="text" placeholder="Enter your name" value="" id="suName" > <label>Email:</label> <input type="email" name="email" id="suEmail" placeholder="Enter a valid email address"> <label>Password:</label> <input type="password" placeholder="Enter your password" name="password" id="suPassword" > <input class="submit-button su-submit" type="submit" id="mySUButton"> </form> </div> <h2> Inscreva-se </ h2> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="sign-up"> <form onSubmit="return setBindings();"> <h2>Sign Up</h2> <label>Name:</label> <input type="text" placeholder="Enter your name" value="" id="suName" > <label>Email:</label> <input type="email" name="email" id="suEmail" placeholder="Enter a valid email address"> <label>Password:</label> <input type="password" placeholder="Enter your password" name="password" id="suPassword" > <input class="submit-button su-submit" type="submit" id="mySUButton"> </form> </div> <label> Nome: </ label> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="sign-up"> <form onSubmit="return setBindings();"> <h2>Sign Up</h2> <label>Name:</label> <input type="text" placeholder="Enter your name" value="" id="suName" > <label>Email:</label> <input type="email" name="email" id="suEmail" placeholder="Enter a valid email address"> <label>Password:</label> <input type="password" placeholder="Enter your password" name="password" id="suPassword" > <input class="submit-button su-submit" type="submit" id="mySUButton"> </form> </div> <label> Senha: </ label> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="sign-up"> <form onSubmit="return setBindings();"> <h2>Sign Up</h2> <label>Name:</label> <input type="text" placeholder="Enter your name" value="" id="suName" > <label>Email:</label> <input type="email" name="email" id="suEmail" placeholder="Enter a valid email address"> <label>Password:</label> <input type="password" placeholder="Enter your password" name="password" id="suPassword" > <input class="submit-button su-submit" type="submit" id="mySUButton"> </form> </div> </ form> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="sign-up"> <form onSubmit="return setBindings();"> <h2>Sign Up</h2> <label>Name:</label> <input type="text" placeholder="Enter your name" value="" id="suName" > <label>Email:</label> <input type="email" name="email" id="suEmail" placeholder="Enter a valid email address"> <label>Password:</label> <input type="password" placeholder="Enter your password" name="password" id="suPassword" > <input class="submit-button su-submit" type="submit" id="mySUButton"> </form> </div> 
    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.