It does but there is a trailing comma, not sure if that will be an issue.
Jpadie's method of taking care of the comma is a good one, I simply did it in the JS by setting the loop to -2. So it ignores the last entry in the array we produce.
Code:
for(var i=0;i<=[b][blue]resultsArray.length-2[/blue][/b];i++){
Couple of questions. I am assuming that this script lives within the script tags in the file referenced above. Also what triggers it? Lastly can this code as well as the AJAX setup so it is generic? Just thinking ahead incase I find this useful (pretty sure I will). Thanks
The AJAX script which include the JS script to recreate the dropdown lives in the same page as the html dropdowns that's the entire point.
The trigger is the onChange event of the dropdown. You still don't seem to have understood how this works.
Code:
<html>
...
<script>
function populate(){
Ajax code, and populating code as shown above.
}
</script>
...
<body>
<select name="dropdonwn1" onchange="populate();">
...
</select>
<select name="dropdonwn2">
...
</select>
And
Code:
<?PHP
PHP code to get relevant results from Database.
?>
The onChange event triggers our JS function which holds the Ajax code that calls up the PHP script. The PHP script obtains the results we need by using the value we passed to it through the GET array. It then outputs its values to screen, which our Ajax script can then retrieve.
THe Javascript can then take the results that the Ajax script receives to populate the dropdown.
As far as the generic question goes, I don;t quite understand what you are asking.
The Ajax code is as generic as they come, its simply a conduit to get the results. Whatever you get is provided by the PHP script, and what you do with them in your Javascript is up to you.
----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
Behind the Web, Tips and Tricks for Web Development.