Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bizarre Javascript problem

 
Bob Grossman
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A snippet of Javascript code:


Now here's an alert that appears:



I cannot for the life of me figure out why the various molstruct.indexOf() are returning values of -1 when molstruct clearly contains these strings.

I'm using Safari 5.0.3, MacOS 10.5.8. I don't know whether the same problem occurs in other browsers/systems.

Here's another tidbit: molstruct.replace(/\n/g, ' ').replace(/\r/g, ' ') returns an unchanged value for molstruct. It's almost as if the Javascript methods are operating on an empty string, not molstruct.

Any ideas?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you edit that string in that alert, it is long and not wrapping in the code block.

Are you sure molstruct is a string?



Eric
 
Bob Grossman
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, you hit the nail on the head. I wasn't aware of the typeof operator. Safari thinks the variable is an object, not a string. Now I just have to figure out why Safari doesn't realize it's a string. Thanks for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic