Jump to content

Dynamic Dropdown


Suchy

Recommended Posts

I'm havving troubles filling in a dropdown list with values passed back via AJAX.

 

function city_list (form_id, list_id)
{
   if(httpObject.readyState == 4)
   {
                var cities = httpObject.responseText;
                for (i=0; i<cities.length-1; i++)
               {
                     var city = cities[i].split(":");
                     document.form_id.list_id.options[document.form_id.list_id.options.length] = new Option (city[1] , city[0]);
                }
   }
}

 

This does not work, however when I manualy type in the form_id and the list_id it works.

So if the form_id = city_form, list_id = city_names

 

changing the line

document.form_id.list_id.options[document.form_id.list_id.options.length] = new Option (city[1] , city[0]);

 

to

 

document.city_form.city_names.options[document.city_form.city_names.options.length] = new Option (city[1] , city[0]);

 

it works. How can I get the first example to work, I want to pass the form and list info to the function.

Link to comment
https://forums.phpfreaks.com/topic/225911-dynamic-dropdown/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.