Jump to content

setTimeout and variables!!


acidglitter

Recommended Posts

i have a function that starts out..

function confirm(trID, data){

 

and inside it i have

setTimeout(okaythen(trID),2000);

 

 

after the function ends i have

function okaythen(trID){
document.getElementById('row_1_2').innerHTML = trID;
}

 

right now i'm just trying to get the <td> to show its id (trID) just to make sure it works, but it doesn't for some reason. if i change the setTimeout to setTimeout(okaythen('okay'),2000); then inside the <td> it shows 'okay', but for some reason it won't carry a variable... i spent forever trying to fix this. i also tried setTimeout("okaythen(" + trID + ")",2000); but that won't work either. does anyone know what i can do to fix this??

Link to comment
Share on other sites

You'll lose the function scope in setTimeout, you can use global variables or the variable value.

 

e.g.

setTimeout("okaythen('" + trID + "')",2000); 

Notice the single quote ' before the " + to make the value as a string

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.