Forum Moderators: open

Message Too Old, No Replies

Javascript onchange not firing.SOMETIMES

         

kcackler

6:26 pm on Oct 15, 2008 (gmt 0)

10+ Year Member



Can someone please tell me what is wrong with the javascript at URL REMOVED

I don't have any problems with the javascript working and neither does my client. But some schools administrators and parents that load the page are having problems with it not working. The only thing I can do to break the page for myself is to disable javascript (Which then gives the user an error about javascript not being available) or set my security settings to "High" in IE.

I'm at the end of my rope here trying to figure this problem out..

If anyone just notices something terribly wrong, please let me know. I've exhausted my resources trying to fix this problem (Which is very hard to do since I'm not the one actually experiencing the problem)

Kevin

[edited by: Fotiman at 1:57 pm (utc) on Oct. 17, 2008]
[edit reason] No URLS per the TOS please. [/edit]

Demaestro

6:32 pm on Oct 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld kcackler.

Next time no URLs as per the TOS of this site.

I would try changing the logic to use to onblur instead of onchange

Try that and report back. Hopefully that works for you.

Let me know

[edited by: Demaestro at 6:32 pm (utc) on Oct. 15, 2008]

kcackler

6:44 pm on Oct 15, 2008 (gmt 0)

10+ Year Member



Sorry about the link. I'm new here *embarassed*

I cannot onchange to onblur, as the end users expect instant gratification when they click that state in the select menu. Thank you for the suggestion (really) but changing to onblur isn't really an option here in this particular case. This site is a makeover of an older site that functioned in exactly the same way, using onchange for the select menus. The only difference is that the old site actually WORKS for all of the users :)

Kevin

Demaestro

8:00 pm on Oct 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you have any information about what browser and OS the person/people experiencing this are using?

I am wondering if it is because of an older browser.

Onchange should work especially for select boxes....

You can try leaving the OnChange and add an onBlur that calls the same function...

<select name="state" id="state" size="15" onchange="updateschools(this.options[this.selectedIndex].value);" onblur="updateschools(this.options[this.selectedIndex].value);">

<select name="schools" id="schools" size="15" onchange="updatebuttons();" onblur="updatebuttons();">

You can even add an onClick method.

Really the best thing you can do if this won't work is have someone give you a detailed report of the error.

Ask them when they get it to record.
1) The exact string in the address bar
2) The OS of the machine
3) The browser type and version
4) Which item did they select
5) Did they select an item before and it worked?
6) How did they select the item? Clicking? Keyboard arrows? Tab + space bar?
7) What exactly happens when it errors? A message? Nothing happens? Browser crashes?

Once you have this type of information you will have an easier time debugging it.... the worst errors are the ones you can't reproduce.... once you can reproduce the error it will be so much easier to debug.

kcackler

8:08 pm on Oct 15, 2008 (gmt 0)

10+ Year Member



I've duplicated their environment to a "T" (IE7, security Medium, Windows XP and Vista) and I still can't reproduce the problem. The thing that is getting me is that, for instance, at a public school system that is having trouble: About 80% of their computers can access and run the page just fine, but the other 20% cannot. I've been on the phone with the IT guy from the school for the past several days, trying to find a common denominator between the machines, and so far we've discovered nothing.

And, amazingly enough, I've just discovered something else that makes my job even more difficult - The computers that cannot run the javascript on the page linked to above....Can run another javascript form on the same website that is using onchange events on select boxes.

So basically, I've got onchange events on one form that aren't working for the user, but the onchange events on another form are working for the user....and I've got no idea why (I even took remote control of the computer and could not get it to work).

The only thing I've discovered is that my javascript was missing a semi-colon in one of the functions. I'm not sure if that was the cause of the problems (It was the function that updated the second select box, so it's entirely possible) because I know JS doesn't require semicolons.....But I'm hopeful that it will magically be fixed after adding it. I'm waiting to hear back from the user to see if it solves their issues.

Hopefully that's all it is, and I can rest peacefully :)

Thanks again for your advice.

[edited by: kcackler at 8:11 pm (utc) on Oct. 15, 2008]

kcackler

8:08 pm on Oct 15, 2008 (gmt 0)

10+ Year Member



Duplicate post...

Demaestro

8:56 pm on Oct 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The semicolon could have been it.

I have seen that cause issues before.

I hope for your sake that it is.

kcackler

9:17 pm on Oct 15, 2008 (gmt 0)

10+ Year Member



Unfortunately, I don't think that was the underlying cause of the issues. The other form that I spoke of was also missing a semicolon on that line (The forms are somewhat the same) but the user was able to load that form and use it just fine...

We'll continue our search.

If you have any other ideas, please let me know.

Demaestro

9:31 pm on Oct 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hmmm the only other thing coming to me at this time is how you are linking the JS file

<script type="text/javascript" src="find_my_school.js.php"></script>

maybe it needs a slash or some computers mess up the path?

<script type="text/javascript" src="/find_my_school.js.php"></script>

Also it could be that they don't like the file extension of your JS file and ignore it because it doesn't end in .JS.. I am stretching here now though...

It would be great if we knew what error they are getting..... no such function.... x is not defined.... like what is the error?

[edited by: Demaestro at 9:32 pm (utc) on Oct. 15, 2008]

kcackler

9:44 pm on Oct 15, 2008 (gmt 0)

10+ Year Member



Nope - Neither of those apply either (Frustrating I know). The other page that I mentioned pulls a javascript file in with <script type="text/javascript" src="sports.js.php?school_id=xx"></script> and they are able to utilize that page just fine.

From what I understand - There are no errors. The second list just doesn't update. I'm about to give up and throw an alert into the function to see if that is even triggered.....

kcackler

4:00 pm on Oct 16, 2008 (gmt 0)

10+ Year Member



Well - It seems the issue has been sorted...And it doesn't make any sense to me.

Before I had the onchange function being passed an argument, ie onchange="updatebox(this.options[this.selectedIndex].value);"

Once I changed the function to just updatebox() and had the function itself grab the value, everything is working fine for everyone......It really doesn't make sense to me at all.

Demaestro

4:36 pm on Oct 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I see what you did there... the only way I could try to explain it and this could be total BS but.....

Maybe some machines were so slow that they registered the onchange and called the function but hadn't yet in memory selected the item and so when it called the function there was no this.selectedIndex in memory yet.

Sounds far fetched saying it but you never know. Not the first time I have seen something not work locally but work when called from an external file.

kcackler

5:59 pm on Oct 16, 2008 (gmt 0)

10+ Year Member



Your explanation is better than mine: "It was an act of God" :)

Thanks for your help regardless. I'm just glad I can stop worrying about it.

Kevin