Suchy Posted January 28, 2011 Share Posted January 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/225911-dynamic-dropdown/ Share on other sites More sharing options...
sunfighter Posted January 30, 2011 Share Posted January 30, 2011 First, I hope the function city_list () is being calling from the function that is making the ajax request. Second, your not passing the httpRequest object. try making that object universal and setting a variable to it as your first statement. Quote Link to comment https://forums.phpfreaks.com/topic/225911-dynamic-dropdown/#findComment-1167408 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.