SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Zealot trekmp's Avatar
    Join Date
    Dec 2005
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Anything wrong with this code

    The following code works in IE, Firefox, Opera, Netscape but not Safari 1.3.2 and I cannot see why and its driving me mad.

    Code:
    mySelect=document.getElementById('Qualification');
    removeAll(mySelect);		
    
    var myOpt=document.createElement('option');
    myOpt.value="0";
    myOpt.text="-- All --";
    mySelect.options.add(myOpt);
    
    var sOutData=s;
    var x=s.toLowerCase();				
    if(x.indexOf("error")==-1) 	{
    	var sRecord=s.split('|');
    	var cnt=0;
    	var sOutData="";
    	
    	while(cnt<sRecord.length) {
    		sData=sRecord[cnt].split(',');
    		if(sData[0]) {
    			//sOutData+=sData[1];
    			var myOpt=document.createElement('option');
    			myOpt.value=sData[0];
    			myOpt.text=sData[1];
    			mySelect.options.add(myOpt);
    		} else {
    			var myOpt=document.createElement('option');
    			myOpt.value="";
    			myOpt.text="No data";
    			mySelect.options.add(myOpt);						
    		}
    		cnt++;
    	} //end while
    }
    mySelect.disabled=false;
    Why do we exist? What is our purpose?
    >H2O Developments
    >USS Endeavour
    >Hosted@Servage

  2. #2
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What part doesn't work?

  3. #3
    SitePoint Zealot trekmp's Avatar
    Join Date
    Dec 2005
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, just doesn't create any options within the select in Safari browser.

    So anywhere there is mySelect.options.add(myOpt);
    Why do we exist? What is our purpose?
    >H2O Developments
    >USS Endeavour
    >Hosted@Servage

  4. #4
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a cross-browser style that I've used in the past to create options in a select:
    Code:
    var sel = document.getElementById('selectElement');
    //Option(textShown, valueofoption,defaultselected, selected)
    sel.options[sel.options.length] = new Option("text","value",false,false);
    That's faster (and easier) than using the document.createElement methods and should work on all modern browsers (including Safari).

    Give it a try and let me know how it goes.

  5. #5
    SitePoint Zealot trekmp's Avatar
    Join Date
    Dec 2005
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jtrelfa: Cheers for that, works now.
    Why do we exist? What is our purpose?
    >H2O Developments
    >USS Endeavour
    >Hosted@Servage


Bookmarks

Posting Permissions

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