Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: timer

  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    timer

    How could I lock an "Enter" link on an intro page with a 30 second timer that is displayed on the bottom of the page and disables the "Enter" link so that visitors have to wait 30 seconds to read the rules/announcements before entering?
    Last edited by project5; 03-16-2012 at 07:20 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,081
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by project5 View Post
    How could I lock an "Enter" link on an intro page with a 30 second timer that is displayed on the bottom of the page and disables the "Enter" link so that visitors have to wait 30 seconds to read the rules/announcements before entering?
    Code:
    <body onload =  "setTimeout(delayIt, 30000)">
    
    <div id = "mydiv" style="display:none">
    <a href = "http://www.google.com">Link to Google</a>
    </div>
    
    <script type = "text/javascript">
    function delayIt() {
    document.getElementById("mydiv").style.display="block";
    }
    
    </script>
    But people may not be willing to wait that long (especially after the first time) and may simply move on to another site.

    If you actually want to show the seconds counting down, use this:-


    Code:
    <body onload = "startTimer(30)">
    
    <span id="countdown" style="font-weight: bold;">30</span>
    
    <div id = "mydiv" style="display:none">
    <a href = "http://www.google.com">Link to Google</a>
    </div>
    
    <script type = "text/javascript">
    
    var timeInSecs;
    var ticker;
    
    function startTimer(secs){
    timeInSecs = parseInt(secs);
    ticker = setInterval("tick()",1000); 
    tick(); // get the display started right away
    
    }
    
    function tick() {
    var secs = timeInSecs;
    if (secs>0) {
    timeInSecs--;
    }
    else {
    clearInterval(ticker); // stop counting at zero
    document.getElementById("mydiv").style.display="block";
    }
    
    document.getElementById("countdown").innerHTML = secs + " seconds to wait";
    }
    
    </script>
    "A psychiatrist asks a lot of expensive questions that your wife asks for nothing." – Joey Adams
    Last edited by Philip M; 03-16-2012 at 08:42 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by project5 View Post
    How could I lock an "Enter" link on an intro page with a 30 second timer that is displayed on the bottom of the page and disables the "Enter" link so that visitors have to wait 30 seconds to read the rules/announcements before entering?
    You can't actually force people to read anything on a web page. But what you can do is get them to say they have read something whether they have or haven't.

    I wouldn't show a count down timer because I think that would be too distracting for most people while they are trying to read what you really want them to see. If you have a timer display, most will just watch it count down.

    Another option is to use a checkbox that the user must tick to enable the Enter button. The check box would just need an onclick event handler that calls enableEnter() if the checkbox is checked.

    Code:
    <body>
        <div>Rules and Announcements</div>
        <div><button id="btnEnter">Enter</button></div>
        <script type="text/javascript">
            var btnEnterO = document.getElementById('btnEnter');
            btnEnterO.disabled = true;
            function enableEnter(){
                btnEnterO.onclick=function(){
                    window.location.href='url1';
                }
                btnEnterO.disabled = false;
            }
            setTimeout(enableEnter,5000);
        </script>
    </body>
    With a javascript only solution it is too easy to bypass the timer and so in the real world I would use a server side solution.
    Last edited by webdev1958; 03-17-2012 at 02:40 AM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,081
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by webdev1958 View Post
    With a javascript only solution it is too easy to bypass the timer and so in the real world I would use a server side solution.
    If the user is confirming that he accepts the terms and conditions of your site, then it is essential that this is also validated server-side.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by Philip M View Post
    If the user is confirming that he accepts the terms and conditions of your site, then it is essential that this is also validated server-side.
    yep . Validating user inputs is part of normal "good practice" server side processing. I think you'll find that validating user inputs server side is a "must do" has been mentioned ad infinitum all over the place and it doesn't do any harm to mention it again

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,081
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by webdev1958 View Post
    yep . Validating user inputs is part of normal "good practice" server side processing. I think you'll find that validating user inputs server side is a "must do" has been mentioned ad infinitum all over the place and it doesn't do any harm to mention it again
    And it gives you yet another opportunity to increase your post count!

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    [ot]

    Quote Originally Posted by Philip M View Post
    And it gives you yet another opportunity to increase your post count!
    What's the deal with post count? Is there a prize after reaching a target? I doubt it.

    Post count to me means nothing. I look at what people say, not how many times they have said something. Someone could make their first post on one website while having 20,000 posts on another website

    So it's a case of - yeah whatever

    [/ot]
    Last edited by webdev1958; 03-17-2012 at 10:52 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •