469,319 Members | 2,466 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

Javascript program fixed by alert statements???

I was wondering if anyone else has had an experience like this. I have
a Java function about 75 lines long. It's not very complicated...
nothing fancy... just dynamically building SELECT menus and setting a
specific one to be the SELECTED default option.

Anyway, the function would crap out at a certain line in the code, and
I couldn't (and still can't) figure out why it died at this specific
line. However, if I inserted an alert statement pretty much anywhere
in the code (and it didn't matter what the alert said), the code would
work perfectly fine. I take the alert out, crap out at the same line.
Put it back in, code works perfectly fine again.

Has anyone else had strange issues like this before?

Feb 9 '07 #1
3 1120
Lee
The alMIGHTY N said:
>
I was wondering if anyone else has had an experience like this. I have
a Java function about 75 lines long. It's not very complicated...
It's not a Java function. Javascript contains the word "Java"
because the marketing people thought it sounded cool.
>nothing fancy... just dynamically building SELECT menus and setting a
specific one to be the SELECTED default option.

Anyway, the function would crap out at a certain line in the code, and
I couldn't (and still can't) figure out why it died at this specific
line. However, if I inserted an alert statement pretty much anywhere
in the code (and it didn't matter what the alert said), the code would
work perfectly fine. I take the alert out, crap out at the same line.
Put it back in, code works perfectly fine again.

Has anyone else had strange issues like this before?
Yes. You're doing something dynamic. Whatever it is may not happen
synchronously (ie, some task may not be finished yet when you get to
some line that depends on it having finished. The alert() gives it
time to finish, or causes something to be re-rendered, etc.

In general, it means you're doing something the wrong way.
It would help to know exactly (ie, copy and paste code into a post)
what you're doing and in which browser you're seeing the behavior.
--

Feb 9 '07 #2
On Feb 9, 11:09 am, Lee <REM0VElbspamt...@cox.netwrote:
The alMIGHTY N said:
I was wondering if anyone else has had an experience like this. I have
a Java function about 75 lines long. It's not very complicated...

It's not a Java function. Javascript contains the word "Java"
because the marketing people thought it sounded cool.
Just a typo on my part. I'm working with a lot of Java developers now
so I have to keep switching my mindset between Javascript and Java.
Yes. You're doing something dynamic. Whatever it is may not happen
synchronously (ie, some task may not be finished yet when you get to
some line that depends on it having finished. The alert() gives it
time to finish, or causes something to be re-rendered, etc.

In general, it means you're doing something the wrong way.
It would help to know exactly (ie, copy and paste code into a post)
what you're doing and in which browser you're seeing the behavior.
That sounds like that could be the problem. I'll take another look. I
have these arrays storing the possible options that go in the drop-
down menus. When the user selects an option in one drop-down menu, the
options in two "child" menus is supposed to change to appropriate
values.

This function I'm talking about basically just handles that... seeing
what option the user selected in the first menu and then repopulating
the existing arrays with the right values.

I didn't think timing would be an issue because it's only six or seven
options in each of the two drop-down menus... but maybe I
overestimated Javascript LOL.

Thanks!

Feb 9 '07 #3
Hi,

The alMIGHTY N wrote:

<snip>
I didn't think timing would be an issue because it's only six or seven
options in each of the two drop-down menus... but maybe I
overestimated Javascript LOL.
Timing issues don't mean that something is taking a long time. It only
means that something occurs at the wrong time.

For example, your code may try to access a variable before it is defined
or initialized, and you get a null reference exception. Or, you try to
access something in the HTML DOM too early, before the page is parsed.
If the script is blocked by the alert, the HTML engine has more time to
finish parsing the code, and then the error doesn't occur.

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 9 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Gowhera Hussain | last post: by
11 posts views Thread by George Hester | last post: by
1 post views Thread by smorrey | last post: by
pbmods
1 post views Thread by pbmods | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.