Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For this you will have to get into AJAX, and I highly recommend using jQuery's implementation. You will also need to get a good grip on JSON string coding and decoding.</p> <p>The basic Idea of your code will be like so:</p> <pre><code>// listen for user to change the &lt;select&gt; item $('select#park').on('change', function(){ $.ajax({ url: 'getrides.php' // send a park id to this script ,cache: false // do not cache results in browser ,type: 'POST' // send POST to getrides.php ,data: {'park_id': $('select#park').val()} // getrides.php will receive $_POST['park_id'] ,dataType: 'json' // this AJAX call expects a JSON string as a return value ,success: function(data){ // the data variable will be converted to an array from JSON // check out all your data console.log(data); // loop through your array $.each(data, function(index, info){ // see your array indexes console.log(index); // see data in each array item console.log(info); }); } }); </code></pre> <p><strong>UPDATE</strong></p> <p>You can also load all of the parks and rides into a Javascript array and based on what the user chooses from the dropdown then populate the second dropdown with those array members.</p> <pre><code>&lt;script&gt; var rides = new Array(); rides['park1'].push('ride1'); rides['park1'].push('ride2'); rides['park1'].push('ride3'); rides['park1'].push('ride4'); rides['park1'].push('ride5'); rides['park2'].push('ride1'); rides['park2'].push('ride2'); rides['park2'].push('ride3'); rides['park2'].push('ride4'); rides['park2'].push('ride5'); // listen for user to change the &lt;select&gt; item $('select#park').on('change', function(){ // clear current DD options $('select#rides').html(); // loop through array of available rides for selected park $.each(rides[''+$(this).val()+''], function(index, value){ // dynamically create the proper DD options $('select#rides').append('&lt;option&gt;'+value+'&lt;/option&gt;'); }); }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload