Solved

split function in Safari

Posted on 2007-11-18
2
939 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
ID: 20308405
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
ID: 31409817
That was it. Thank you very much.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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 nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Suggested Courses

630 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