AJAX PHP issue

software development

#1

I’m trying to populate a select list of Cities when a user selects a state. The update occurs when the state field loses the focus (onblur).

I can select the data correctly from the database, but I’m having a horrid time getting the returned data into the option fields. I am Javascript clueless, but I’m trying to learn. I could’ve had this done hours ago if I had just used PHP and reloaded the page.

Here’s the part I’m having issues with:

===================Here’s the actual body part.

State: <?= select_state(); ?>
City:

I need this to populate the city dropdown from the HTTP response.

================================
Angela Gann
CrimsonDryad Web Design Services
Web Design, Custom Software Development
http://www.crimsondryad.com


#2

Here.

function handleHttpResponse() { if (http.readyState == 4) { if (http.responseText.indexOf('invalid') == -1) { cities = http.responseText.split(","); options = document.getElementById('city').options; options.length = 0; for (counter = 0; counter < cities.length; counter ) { options[options.length] = new Option(cities[counter]); } } } }1. You were using the wrong variables in the loop
2. Unnecessary to set the length property - adding option increases it automatically

:cool: [color=#6600CC]Atropos[/color] | openvein.org


#3

Thanks a ton. Like I said, I’m Javascript clueless, though I’m trying to learn. :slight_smile:

I appreciate your help.

================================
Angela Gann
CrimsonDryad Web Design Services
Web Design, Custom Software Development
http://www.crimsondryad.com