PDA

View Full Version : setTimeout not passing variables



Oziam
02-03-2011, 12:43 AM
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


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


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

Nile
02-03-2011, 01:14 AM
Try:


setTimeout("processForm("+formname+")", 1500);

function processForm(formname){

// do something with formname
}

Oziam
02-03-2011, 02:10 AM
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!

Nile
02-03-2011, 03:12 AM
Okay, good luck