Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-16-2012, 02:16 PM   PM User | #1
amuha07
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
amuha07 is an unknown quantity at this point
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;
});
});
amuha07 is offline   Reply With Quote
Old 11-16-2012, 03:36 PM   PM User | #2
niralsoni
Regular Coder

 
Join Date: Mar 2008
Location: London
Posts: 129
Thanks: 1
Thanked 31 Times in 31 Posts
niralsoni is an unknown quantity at this point
try this -

Code:
// delay in milli seconds
window.setTimeout('$("#basic-modal .basic").onclick()',20000);
niralsoni is online now   Reply With Quote
Old 11-16-2012, 10:00 PM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,451
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:14 AM.


Advertisement
Log in to turn off these ads.