Changing State/Province/Region drop box.(Used, html,php)

itunes89

New Member
Reaction score
0
I need help. I have this Country box. When it pick a difrent country it needs to change the State/Province/Region box. I have tired this with php and html and I just can't get it to work. Please help.
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
What you need is JavaScript. I suggest you use the jQuery framework as it eases the use of JavaScript.

You could do
Code:
$('#countries').change(function () { // bind the change event to your select input
    var country = $(this).val(); // retrieve the selected country
    $.get('fetch_states.php', {country: country}, function (res) { // using ajax, we retrieve the list of states/provinces associated with the country
        var states = res.split('\n'); // split the ajax result into spaces, assuming the php script placed LF between each state entry
        var html = ''; // create a buffer to handle the html
        for (var i = 0; i < states.length; i++) {
            html += '<option>' + states[i] + '</option>'; // append an option to the select
        }
        $('#states').html(html); // set the html buffer as the inner html of the #states select
    });
});
This assumes you have some sort of database which sorts all the info. Then a php script, in this case, fetch-states.php, fetches the states associated with the country.
You would need to do this again when the states select gets changed.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top