I am developing a small function for my site where the shape of the sign is automatically displayed in the navigation bar when the site is opened, but only if a certain cookie is not set. Then, after 10 seconds, the form will disappear.
It should also remain open if the user has selected one of the inputs of the OR form, if one of the inputs contains content. ( #user-pest or #pass-pest ).
Most of them work as intended, however, even if one of the inputs is selected or contains content, after 10 seconds the form will disappear from the page.
Below is the JavaScript (and jQuery ) code I am using ( updated ).
$(document).ready(function(){ // hide sign in form function hideForm(){ // function for updating elements $("#darknet-login-nav").css("display", "none"); $(".index-outer").css("height", "100px"); $(".index-inner").css("width", "438px"); $(".index-inner").css("top", "-10px"); $("#darknet-mast").css("font-size", "97px"); } function hideFormSet(){ // function used for updating elements and setting cookie hideForm(); document.cookie = "signinNav=set"; } var checkDisplayed = getCookie("signinNav"); // get cookie contents if(checkDisplayed == "set"){ hideForm(); // if cookie is set, hide the form } else { // if it isn't var hideInterval = setInterval(hideFormSet, 10000); // after 10 seconds, call hideFormSet function if($("#user-pest").is(':focus') || $("#pass-pest").is(':focus')){ clearInterval(hideInterval); // if one of the inputs are focused on, stop the interval } else { hideInterval; // if they aren't focused, start the interval } } });
and this is my simplified markup.
<div class="darknet-nav-login-form" id="darknet-login-nav"> <form action="" method="post"> <input type="text" name="username" id="user-pest" placeholder="Username" autocomplete="off"><br> <input type="password" name="password" id="pass-pest" placeholder="Password" autocomplete="off"><br> </form> </div>
I am still very new to JavaScript, so we will be grateful for any pointers and corrections.
EDIT: please check my updated code above.
Even if the inclusion of inputs is focused, the interval will continue, not stop.
thanks