PHP from javascript?!?

I’m trying to rewrite a javascript I found to be able to use mysql database.

The script is autopopulating selectfields and are doing it from arrays like this:

states['Canada'] = new Array('Alberta','British Columbia','Ontario');


cities['Canada']['Alberta']          = new Array('Edmonton','Calgary');

It gets the variable from the form like this:

function setStates() {
  cntrySel = document.getElementById('country');
  stateList = states[cntrySel.value];
  changeSelect('state', stateList, stateList);

How can I get these out of an mysql database?!?!

Thanks in advance…

You want to replace the hardcoded arrays with something in a database?

So, “javascript from PHP” not “PHP from javascript”, right?

Select the appropriate rows and echo JavaScript code exactly like that above

Which part do you need help with?

Well, I think if I can figure out the new Array part I’m pretty much on the way… I think it must be something like:

select from states where countryID=country???

Hope this make sense…

You need to print out all the states for all the countries, don’t you? So no WHERE clause, just select the country and state columns from all rows.

Or did you want to add a database AND rewrite all the JavaScript? AJAX?