Results 1 to 4 of 4

Thread: setTimeout not passing variables

  1. #1
    Join Date
    Jan 2011
    Location
    QLD, Australia
    Posts
    23
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default setTimeout not passing variables

    hi,

    I am trying to set a timeout then call another function
    after timeout expires, this works OK using;

    setTimeout("processForm()", 1500);

    it works fine if I have the processForm variables already predefined,

    e.g

    Code:
    var formname = 'form1';
    
    function processForm(){
    
    // do something with formname
    }
    but if i try to pass them within the setTimeout function it doesn't work?

    e.g

    Code:
    setTimeout("processForm(formname)", 1500);
    
    function processForm(formname){
    
    // do something with formname
    }
    this will result in undefined formname error!
    I have tried to remove and change the quotes around but still get errors??

    any Ideas please

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Try:
    Code:
    setTimeout("processForm("+formname+")", 1500);
    
    function processForm(formname){
    
    // do something with formname
    }
    Jeremy | jfein.net

  3. #3
    Join Date
    Jan 2011
    Location
    QLD, Australia
    Posts
    23
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    thanks, but that didn't work either.

    However I did figure it out, I just declared the formid as a global variable!
    now it works within other functions without having to redeclare it!

    Cheers!

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Okay, good luck
    Jeremy | jfein.net

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
  •