SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    501
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pausing a function

    kinda like how an alert() will stop everything until the user interacts with it - i'm wanting to stop the flow of everything until another event happens. for example...

    onclick="final_function(first_function('Does 1 + 5 = 6?'));"

    function first_function(message) {
    // some document.createElement() stuff
    // buttons that will return true or false
    }
    function final_function(status) {
    if (status) {
    // true - so do something with it
    } else {
    // false - don't do anything
    }
    }

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Only alert(), confirm(), and prompt() can do that. If you don't want to do that, you'll have to have multiple functions and use setTimeout/setInterval or event handlers to call the next function.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    501
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok... how about dynamically calling on another function like this. is there a way to "pass" a function into another?

    onclick="whatever('testing', 'something()');"
    onclick="whatever('testing', 'another()');"

    function whatever(msg, funct) {
    var a = confirm(msg);
    funct(a);
    }

    function something(status) {
    if (status) {
    // something
    } else {
    // something else
    }
    }

    function another(status) {
    if (status) {
    // something
    } else {
    // something else
    }
    }

  4. #4
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    501
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, this semi-works...but i'm having difficulty just keeping whatever() empty without variables while being called within msgBox().

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    function msgBox(subject, message, funct) {
    	var agree = confirm("Do you know what you're doing?");
    	funct("yo yo yo");
    }
    function whatever(status) {
    	alert(status);
    }
    </script>
    </head>
    <body>
    <button type="button" onclick="msgBox('Test', 'Testing...', function() { whatever(''); });">Click</button>
    </body>
    </html>

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NokX View Post
    ok... how about dynamically calling on another function like this. is there a way to "pass" a function into another?
    Yes. In javascript, functions are objects. Try this:
    HTML Code:
    <input type="button" onclick="whatever('testing', something);" />
    <input type="button" onclick="whatever('testing', another);" />
    <script>
    function whatever(msg, funct) {
         var a = confirm(msg);
         funct(a);
    }
    
    function something(status) {
         if (status) {
         // something
         } else {
         // something else
         }
    }
    
    function another(status) {
         if (status) {
         // something
         } else {
         // something else
         }
    }
    </script>


Bookmarks

Posting Permissions

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