javascript - Valid inputs and use animation untill page load -
i need validate filled inputs , on submit if inputs valid show load animation till next page shown. can check validation 1 one, not know how collect them in one. maybe there more simple way check inputs validation? did validations inside inputs in code below. here inputs type need validate , on success show load animation until page refresh page:
<form action="" method="post" enctype="multipart/form-data" name="formz" > <div> <label>name: </label> <input type="text" onkeydown="return keydown.call(this,event)" onchange="value = value.replace(/^\s+/,'')" pattern=".{3,20}" name="name" required> </div> <div> <label>surname: </label> <input type="text" onkeydown="return keydown.call(this,event)" onchange="value = value.replace(/^\s+/,'')" pattern=".{3,20}" name="surname" required> </div> <div> <label>unic number: </label> <input type="text" onkeydown="return keydown.call(this,event)" onchange="value = value.replace(/^\s+/,'')" pattern=".{7,7}" maxlength='7' name="unicnumb" required /> </div> <div> <label>select:</label> <select name="select" id="select" required> <option value="0" selected disabled >select</option> <option value="1">select1</option> <option value="2">select2</option> </select> </div> <div> <label>phone: </label> <input type="text" name="phone" id="phone" placeholder="+xxx(xx) xxx-xx-xx" required> </div> <div> <label for="epoct">e-mail</label> <input type="email" pattern="[a-za-z0-9.-_]{1,}@[a-za-z.-]{2,}[.]{1}[a-za-z]{2,}" class="form-control input-sm" name="epoct" id="epoct" required> </div> <button type="submit" name="button" id="button">done</button> </form>
this outline how i've handled successive form validation jquery:
$(document).ready(function() { $( "#button" ).submit(function( event ) { if ( /* validation fails first form element */ ) { // stop form submission event.preventdefault(); // display error message $( "#firstformfieldid" ).append("<span>incorrect entry</span>"); // break out of function ensure validation continues if , if condition met return false; } if ( /* validation fails second form element */ ) { // stop form submission event.preventdefault(); // display error message $( "#secondformfieldid" ).append("<span>incorrect entry</span>"); // break out of function ensure validation continues if , if condition met return false; } if ( /* validation fails third form element */ ) { // stop form submission event.preventdefault(); // display error message $( "#thirdformfieldid" ).append("<span>incorrect entry</span>"); // break out of function ensure validation continues if , if condition met return false; } // ... repeat many form fields need validation // if validation criteria met, can deploy loading animation here :) /* loading animation goes here */ }); });
you can imagine variations template. instance, rather appending <span>
s, add empty <span>
s intended contain error messages html. if error message needs displayed, use jquery add text of error message corresponding <span>
. actual implementation depend on you, style has worked me.
Comments
Post a Comment