Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript keeps undefining my vars, it's harshing my buzz. Help?

Tags:

javascript

This is my first experience with javascript, and... Well... Ugh. Here's what's happening:

function step_1(id) {
    //blah blah
    step_2(id);
}
function step_2(id) {
    //blah blah
    step_3(id);
}
function step_3(id) {
    //blah blah
    alert(id);
}

step_1(0); // I can stick any number here, same thing happens...

The alert pops up and says "Undefined". But, if I throw an alert(id); in step_2, then both alerts say "0".

Why/how is id undefined? What am I doing wrong?

I've even tried reassigning id in each function, like:

var nid = id;
step_2(nid);

etc... But that still doesn't work without the alerts.

EDIT: Since my example apparently works fine, perhaps it would help to look at the blah blah that's going on in my code. It works fine, unless I take out the alert(id); on line 11.

like image 480
Keene Maverick Avatar asked Dec 22 '22 04:12

Keene Maverick


2 Answers

There's a difference between step_2 and step2. And all your other little steps ...

like image 124
Robusto Avatar answered Feb 16 '23 00:02

Robusto


You have a line (line 30) at the end of checkUpload that calls itself without any parameters:

    window.setTimeout('checkUpload();', 333);

It seems like this is what you meant to do:

    window.setTimeout(function() { checkUpload(id); }, 333);

    // which is the equivalent to:
    // window.setTimeout("checkUpload(" + id + ");", 333);
like image 20
Jeff Meatball Yang Avatar answered Feb 16 '23 00:02

Jeff Meatball Yang