0

I am trying to check if the user has clicked in an input with in a given time 3 seconds, if not hide the panel.

But my checkInput is not working. If I put it in the main jQuery if just shows for the 3 seconds and then disapears.

My Css is just display:none.

Any help would be good.

<div class="sign-up">
            <h4>Login</h4>
            <div class="sign-up-line">
            <asp:Label ID="lbl_usr_name" runat="server" Text="User name" /><br />
            <asp:TextBox ID="txt_usr_name" runat="server" CssClass="form-control" />
                                    </div>
            <div class="sign-up-line">
            <asp:Label ID="lbl_password" runat="server" Text="Password" /><br />
            <asp:TextBox ID="txt_password" runat="server" CssClass="form-control" TextMode="Password"/>
                                    </div>
            <div class="sign-up-text">
             <p>Forgotten your password <a href="#">click here</a></p>
             <p>Problems logging in <a href="#">click here</a></p>
             </div>
            </div>

var signUpPanel = $('.sign-up');
var userName = $('#txt_usr_name');
var password = $('#txt_password');


$('.sign-up-link').on('click', function () {
  if (signUpPanel.is(":hidden")) {
      userName.val('');
      password.val('');

      signUpPanel.slideDown('slow');

      checkInput();

   } else {
          signUpPanel.hide();

   }

});

function checkInput() {
     //set timer
     setTimeout(function () {
        if (userName.val() && password.val()) {
            signUpPanel.hide();
          } else if (!userName.val() && !password.val()) {
            signUpPanel.show();
          }
        }, 3000);
      }
2
  • Post a complete code example please. Commented Sep 3, 2014 at 15:15
  • In your checkInput() function you are hiding the panel if there IS a username and password value. Surely you want it the other way round? Commented Sep 3, 2014 at 15:37

2 Answers 2

2

In your code, it doesn't have any timer functions or delay functions! So, assuming if there is a code like this:

<input id="clickMe" type="submit" value="Click within 3 Secs" />

If the user has to click within 3 seconds, you can do something like:

$(document).ready(function(){
    var a = setTimeout(function(){
        $("#clickMe").prop("disabled", true).hide();
    }, 3000);
    $("#clickMe").click(function(){
        clearInterval(a);
    });
});

Fiddle: http://jsfiddle.net/ex600p01/1/

Sign up to request clarification or add additional context in comments.

5 Comments

Yes, that's what you need right? @StudentRik What you want it to do after 3 seconds?
Okay, so you wanna say if the user clicks it, it should not disappear right?
Could I do this on the blur event as well?
@StudentRik yes you can! :)
For maximum correctness you should be using clearTimeout not clearInterval. Just sayin' ;)
0

You could look at it differently, EG: Hide the panel after 3 seconds unless an input is clicked:

var signupTimeout = setTimeout(function(){signUpPanel.hide();}, 3000);
signUpPanel.on('click focus', 'input', function () {
    clearTimeout(signupTimeout);
});

http://jsfiddle.net/tjhp342j/1/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.