javascript - loading screen appears after jquery alert -
i'm trying create loading screen appear when form being submitted, works great except on safari, problem if click enter or submit alert appears when click okay alert go away loading appears because of submit event , doesn't go away. i've tried numerous cant seem figure out, i'm beginner in jquery.
to summarize, on safari after alert, loading screen appears when it's not suppose , doesn't go away.
preferably loading screen appear when form being submitted. or alternative loading screen not show in safari browser.
<script> var form = document.getelementbyid('formid'); // form has have id: <form id="formid"> var ua = navigator.useragent.tolowercase(); if (ua.indexof('safari') != -1) { if (ua.indexof('chrome') > -1) { } else { form.novalidate = true; form.addeventlistener('submit', function(event) { /*listen form submitting */ if (!event.target.checkvalidity()) { event.preventdefault(); /*dismiss default functionality*/ alert('please, fill form before submit'); /*error message*/ $("#formid").attr("id", "form"); $(".circularg1").addclass("active"); $(".circularbrg").addclass("active"); } }, false); } } </script> <!--loading screen appears while form submit's--> <script type="text/javascript"> $(document).ready(function() { $('#formid').submit(function() { var pass = true; //some validations if (pass == false) { return false; $(".circularg1").addclass('active'); //hides loading if clicked $(".circularbrg").addclass('active'); // hides loading if clicked } else { $(".circularg1, .active").removeclass('active'); //shows loading if clicked $(".circularbrg, .active").removeclass('active'); // shows loading if clicked } }); }); </script> <!--^--end--^--> <!-- 3. add script function of hamburger menu --> <script> $(document).ready(function() { $(".icon").on("click", function() { $("header .nav ul").toggleclass("open", 200); }); }); </script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="http://code.jquery.com/ui/jquery-ui-git.js"></script> <div class="circularg1 active"> <div id="circularg_1" class="circularg"></div> <div id="circularg_2" class="circularg"></div> <div id="circularg_3" class="circularg"></div> <div id="circularg_4" class="circularg"></div> <div id="circularg_5" class="circularg"></div> <div id="circularg_6" class="circularg"></div> <div id="circularg_7" class="circularg"></div> <div id="circularg_8" class="circularg"></div> </div> <div class="circularbrg active"></div> <form id="formid" class="form" action="" method="post"> <input name="fname" type="text" placeholder="first name" maxlength="50" min="2" required> <input name="lname" type="text" placeholder="last name" maxlength="50" min="2" required> <input type="submit" name="submit" class="submit"> </form>
the best way resolve issue remove alert line altogether , use different method. example, add div inside form html:
<div id="form-message"></div> then in jquery, replace alert line with:
$('#form-message').text('please, fill form before submit'); this better in terms of usability actual alerts (if ever) used on websites these days.
hope helps!
Comments
Post a Comment