Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.