I have a form in which i use javascript to set the select element options depending on type of property (house, flat, etc). it is working now when I am accessing the list using the document.myForm.priceSelect.options.
I want to access it by id rather than name. Because I want to set the name also along with the options so that when the form is submitted, the name of the list will determine which function to execute. Some code to illustrate:
if(prop_type == 'flat') {
document.getElementById('priceRange').setAttribute('name', 'flatRange');
.....
Now here I am changing the name of the select list called priceRange. How can I also change the options using the id instead of the name like shown below:
document.searchForm.priceRange.options[1]=new Option("10000 - 20000", "10000 - 20000");
Thank you in advance…
UPDATE:
After change: (not working)
if(prop_type == 'flat') {
document.getElementById('priceRange').setAttribute('name', 'flatRange');
document.getElementById('priceRange').options.length=0;
document.getElementById('priceRange').options[0]=new Option("", "");
document.getElementById('priceRange').options[1]=new Option("10000 - 20000", "10000 - 20000");
Simply use