CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   PLZ HELP :/ setTimeOut function (http://www.codingforums.com/showthread.php?t=282384)

amuha07 11-16-2012 02:16 PM

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;
});
});

niralsoni 11-16-2012 03:36 PM

try this -

Code:

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


felgall 11-16-2012 10:00 PM

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.


All times are GMT +1. The time now is 02:17 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.