p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 (http://p2p.wrox.com/forumdisplay.php?f=174)
-   -   Sorting Tables and Safari (http://p2p.wrox.com/showthread.php?t=39872)

HomersGhost March 15th, 2006 03:53 PM

Sorting Tables and Safari
 
The Sorting Tables code borks Safari. Specifically, defining a function within a function produces a parsing error. I've tried a few ideas to make it compatible, but nothing yet. Any ideas?

nzakas March 17th, 2006 09:42 AM

Unfortunately, I don't have a Mac, so I'm unable to test this myself. What is the error message that you get?

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/

Stephen Wilson March 17th, 2006 06:03 PM

Funny I was just trying to figure this out. Thought I made a typeo or something! I tried it in Firefox on mac and it works fine, but not on Safari.

Here's the error from the javascript console if anyone can help:
Value undefined (result of expression sValue1.localeCompare) in not object

On a side note. Love the book. It has been very helpful to me.


nzakas March 17th, 2006 10:17 PM

Perhaps localeCompare isn't available in Safari? If you feel like experimenting, try this JavaScript code:
Code:

alert(String.prototype.localeCompare)
If this outputs "undefined", then that means Safari doesn't support this method. In that case, you can create it yourself:
Code:

String.prototype.localeCompare = function (sOther) {
    if (this < sOther) return -1;
    else if (this > sOther) return 1;
    else return 0;
}


Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/

Stephen Wilson March 18th, 2006 07:09 PM

That worked great. You were right the localeCompare is undefined in safari. Adding that prototype did it! Thank you!



All times are GMT -4. The time now is 08:08 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.