File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes bizarre Javascript problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "bizarre Javascript problem" Watch "bizarre Javascript problem" New topic
Author

bizarre Javascript problem

Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 69
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Dec 18, 2008
Posts: 69
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bizarre Javascript problem