Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically populating Selectboxes from Database
    primarykey
    data
    text
    <p>hope you can help as I'm starting to pull my hair out :) There seems to be loads of links around regarding this but I can't get any of them to work, so I'm just going to ask in straight laymans terms.</p> <p>I have a database... it has fields for Region, Area, Manager, Employee</p> <p>I have a front end form, with select boxes in it...</p> <p>When you choose the Region, I need the Area selectbox to dynamically populate with the relevant areas from the database without refreshing the page</p> <p>Then when the Area selct option is chosen the Manager one needs to populate. and so on.</p> <p>No doubt this needs an ajax/ Jquery solution, of which as I've said there's many articles around about this but I just cannot get them to work. I've NEVER even attempt AJAX before today so sincere apologies if this is a total noob thing to be asking.</p> <p>Any help or guidance would be greatly appreciated. Thankyou!</p> <p>Okay I have this for my Jquery:</p> <pre><code>$(document).ready(function() { $('#Region').change(function() { // remove all options in Area select $('#Area').html(''); // find the new Region selected var selected_region = $('#Region').val(); // get new options from server and put them in your Area select $('#Area').get('Ajax/getArea.php?Region=' + selected_region); }); }); </code></pre> <p>and this for my PHP:</p> <pre><code>&lt;?php // get province id passed in via `post` or `get` $region = $_REQUEST['Region']; // get the districts in that province $query = "SELECT DISTINCT AREA FROM Sales_Execs WHERE Region ='$region'"; // link to your database $link = mysqli_connect("localhost", "root", "", "Quality_Monitoring"); // execute your query $result = mysqli_query($link, $query); // parse the options while($row = mysqli_fetch_assoc($result)) { $options = "&lt;option value=\"".$row['AREA']."\"&gt;".$row['AREA']."&lt;/option&gt;\n "; } // send options echo $options; ?&gt; </code></pre> <p>And still no joy... can anyone spot what I'm missing?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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