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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PLZ HELP :/ setTimeOut function

    Hello dear codingforum members. im newbie in JS so i really ur need help. here is my question. Im working on simple modal project which is developed by eric martin. As it can be seen in the codes. it calls the modal screen when user clicks on demo link or button. however instead of clicking i would like to call tht modal screen automatically after certain time like 20sec later. so can i actually apply setTimeOut in tht JS code ? Thank u !!!

    Regards

    HTML

    <div id='content'>
    <div id='basic-modal'>

    <input type='button' name='basic' value='DEMO' class='basic'/>
    <a href='#' class='basic'>DEMO</a>

    </div>

    <!-- modal content -->
    <div id="basic-modal-content">
    <a href='asdasdasd'><img src="https:/asdasd.jpg" alt="asdasd"></a>

    </div>
    <div style='display:none'>

    </div>
    </div>
    </div>

    JS CODE:

    jQuery(function ($) {
    // Load dialog on page load
    //$('#basic-modal-content').modal();

    // Load dialog on click
    $('#basic-modal .basic').click(function (e) {
    $('#basic-modal-content').modal();

    return false;
    });
    });

  • #2
    Regular Coder
    Join Date
    Mar 2008
    Location
    London
    Posts
    152
    Thanks
    4
    Thanked 42 Times in 42 Posts
    try this -

    Code:
    // delay in milli seconds
    window.setTimeout('$("#basic-modal .basic").onclick()',20000);

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,459
    Thanks
    0
    Thanked 632 Times in 622 Posts
    A better alternative would be:

    Code:
    setTimeout(function() {$('#basic-modal-content').modal();}, 20000);
    1. the first parameter to setTimeout should be a function - not a string that needs to be eval()ed into a function.
    2. You don't need to simulate the click, you just need to call the code that the click calls.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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