Results 1 to 5 of 5

Thread: adding option to select ??

  1. #1

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    adding option to select ??

    here what i'm using to populate an selectbox

    Code:
    function populate(index){
    	document.frm.subCat.options.length = 0;
    	for(x=0;x<subArray[index].length;x++){
    		var newOption = document.createElement("OPTION");
    		newOption.value = subArray[index][x][0];
      		newOption.text = subArray[index][x][1];
    		document.frm.subCat.add (newOption);
    		}
    	}

    works perfect in MSIE, but not netscape!!

    what netscape syntax

    tx

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    What is the error you are getting in NS?
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    ok, i got it to work but in nn
    if there one option to begin with,
    it does not get bigger

    here's my new code:

    Code:
    function populate(index){
    	document.frm.subCat.options.length = 0;
    	for(x=0;x<subArray[index].length;x++){
    		var newOption = new Option(subArray[index][x][1],subArray[index][x][0],false,false);
    		document.frm.subCat.options[x] = newOption;
    		}
    	}

  4. #4
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    This is what I've been doing...

    Code:
    document.myForm.mySelect.options[document.myForm.mySelect.options.length] = new Option(myOptionText, myOptionValue);
    But the only thing I'm finding at W3C, is to actually edit the HTML, and not treat the select as an dynamic object.

    Code:
    var myNewOption = document.createElement("option");
    var myNewOptionText = document.createTextElement(myOptionText);
    
    myNewOption.setAttribute("value", myOptionValue);
    myNewOption.appendChild(myNewOptionText);
    
    document.myForm.mySelect.appendChild(myNewOption);
    I have no idea if that code works, I haven't tested it. I would hope that the ECMA standard would have a shortcut to work with form elements, but I don't know any good documentation on the ECMA standards, just their mapping to the W3C DOM. And I can understand the W3C not suggesting a way to edit options that would undermind the DOM.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  5. #5

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    tx Ciber!

Posting Permissions

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



Click Here to Expand Forum to Full Width