Javascript keeps uncertainty in my records and it pops my noise. Help?

This is my first javascript experience and ... Well ... Ugh. Here's what happens:

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... 

A warning appears and the message "Undefined" appears. But, if I throw a warning (id); in step_2, then both warnings say "0".

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

I even tried to reassign id in each function, for example:

 var nid = id; step_2(nid); 

etc. But it still does not work without warnings.

EDIT: Since my example seems to work just fine, maybe this will help to look at the blah blah that happens in my code . It works fine if I did not get a warning (id); in line 11.

+4
source share
5 answers

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

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

Looks like this is what you wanted to do:

  window.setTimeout(function() { checkUpload(id); }, 333); // which is the equivalent to: // window.setTimeout("checkUpload(" + id + ");", 333); 
+4
source

There is a difference between step_2 and step2. And all your other small steps ...

+5
source

Your script will call checkUpload() with a timer without going through the expected id parameter.

Line 30

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

Change to

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

In the future, as a useful tip, I recommend that you publish your current issue for the first time, and not an example that, in your opinion, illustrates the issue. It just saves time and effort;)

+2
source

_ steps can be the killing of a program, and your little step 2 and step_2 are two different things.

0
source

Help, I don’t know if this answer is consistent as indicated by others, but a couple of observations from viewing your code.

 if (uploadFrame.contentDocument.readyState == 'complete') { if (uploadFrame.contentDocument.getElementById('new_image_id')) { var new_id = uploadFrame.contentDocument.getElementById('new_image_id').innerHTML; 

Really! you should know that "==" is not the correct operator, but "===". General mistake made by students / js users. You can also double-check the identifier, this is 'new_image_id' or 'new_image_'+id .

0
source

Source: https://habr.com/ru/post/1304605/


All Articles