Results 1 to 2 of 2

Thread: Obscure JS issue

Threaded View

  1. #1
    Join Date
    May 2010

    Obscure JS issue

    I wrote this script to split an array, sort each individual array, and then access them both into a select. So as an example, it would split the below array into numbers and letters and then display the numbers in numerical order and also attach the letter next to the number. For some silly reason this works in every browser EXCEPT Safari. From the testing I've been able to do, Safari doesn't access the part where I've bolded in the text. I realize I'm new to posting here, but I think this is actually somewhat interesting (though frustrating)

    The overall biggest issue is that the values of code_sorted remain undefined when creating the select in Safari.

    Thanks in advance ...
    	var temp = new Array(); //temp Array for holding strings
    	var code = new Array(); //holds client codes
    	var name = new Array(); //holds client name
    	var pass = "on"; //sorts the split string to an appropriate case
    	var name_count = 0; //keeps array count for name
    	var code_count = 0; //keeps array count for code
    	var name_sorted = new Array(); //holds final alpha_name_array
    	var code_sorted = new Array(); //holds final code array in relation to alpha
    // "clientCODE|clientNAME|",
    var client_codes = [
    //JS Functions.
    function joinArray(client) //Convert array to string to split.
    	b = client.join("");
    function splitclients(client) //splits string and puts back into temporary array.
    	temp = b.split('|');
    //creates select with name 'clcode' and populates with data from client array
    function create_select(name,code, w)  //Also accepts width from HTML
    document.write('<select name = "s_clcode" onChange="upSel();" id = "s_clcode" class = "ml" style = "width:'+w+'px;"><option value = "0">Please Select:</option>');
      for(var i = 0; i < name.length; i++)
    	 document.write('<option value = "'+code[i]+'">'+name[i]+' - '+code[i]+'</option>');
    function sort_them(temp) //sorts temporary data into either code or name arrays
      for(var i = 0; i < temp.length-1; i++)
    	  if(pass == "on")
    			code[code_count] = temp[i];
    			pass = "off";
    			name[name_count] = temp[i];
    			name_sorted[name_count] = temp[i];
    			pass = "on";
    function alpha_sort(name_sorted, name, code) //sorts the data alphabetically for display and matches code to alpha_sorted name
    	for(var x = 0; x < name_sorted.length; x++)
    		for(var l = 0; l < name_sorted.length; l++)
    			if(name_sorted[x] == name[l])
    			    code_sorted[x] = code[l];
    function clcoder(client, width) //clean protocol, this is the ONLY code that needs called in the HTML
    	alpha_sort(name_sorted, name, code);
    	create_select(name_sorted, code_sorted, width);
    Last edited by Fang; 05-22-2010 at 01:37 AM. Reason: added BB Code

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles