|
-
Nov 6th, 2001, 01:29 PM
#1
Thread Starter
Frenzied Member
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
-
Nov 6th, 2001, 01:41 PM
#2
Frenzied Member
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.
-
Nov 6th, 2001, 01:44 PM
#3
Thread Starter
Frenzied Member
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;
}
}
-
Nov 6th, 2001, 01:58 PM
#4
Frenzied Member
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.
-
Nov 6th, 2001, 02:29 PM
#5
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|