Solved

split function in Safari

Posted on 2007-11-18
2
918 Views
Last Modified: 2013-12-07
Can somebody please help me with the following code snippet? It works in all the browsers except for Safari, and it's driving me nuts. Thanks so much.
function addFileListToSelect(listVal) {

  alert(listVal);            // shows "Tabor-2117.qdfm;" (as expected)

  

  var teststring = "ab-bc-cd";

  var testarray = teststring.split("-");

  alert(testarray[0] + "\n" + testarray[1] + "\n" + testarray[2]);

         // shows "ab\nbc\cd" (as expected)
 

  alert(listVal);            // shows "Tabor-2117.qdfm;" (as expected)

  var fileNameArray = listVal.split("-");

  alert(listVal);            // shows "Tabor-2117.qdfm;" (as expected)

  if(fileNameArray == null) alert("null");

                             // shows "null" (huh???!!!)        

}

Open in new window

0
Comment
Question by:tjgquicken
2 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
Comment Utility
What are you sending into the function? If it's not a string, you might get unexpected results.

If you make sure that it's a string that you are using the split method on, does it change things?

var fileNameArray = String(listVal).split("-");
0
 

Author Closing Comment

by:tjgquicken
Comment Utility
That was it. Thank you very much.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Internet is a big network which is formed by connecting multiple small networks.It is a platform for all the users which are connected to it.Internet act as platform in different fields. Such as: Internet  as a collaboration platform. Internet  as…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now