Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filling list

Status
Not open for further replies.

Qrosity

Technical User
Jan 9, 2008
14
ES
Is there any problem in this function?
It worked out pretty well till I decided to substitute the real name of the list with a var, cause I need to reuse the function for several lists...
Code:
function fillSubCat2(thelist,val1,val2){
document.forms['drop_list'].thelist.options.length = 0;
document.forms['drop_list'].thelist.options[0] = new Option(val2,val1);
}
 
Well, this will throw an error for sure.. :p

Code:
This will access the element with id "thelist":
document.forms['drop_list'].thelist

This will access the element with id set in variable "thelist":
document.forms['drop_list']['thelist']

You must use the later example instead.

Also you cannot set the length property on the options.

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
Thanks lowet, I wasn't trying to set the length property, I was deleting old options from the list...
Thank's for your tip !!
 
Good to hear :)
And btw, I was wrong. You can set the length property.. :p

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top