Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are going to have to write a JavaScript function that retrieves the selected value or option from the first HTML select field. This function commonly writes out a new URL path to the current page with the addition of some concatonated Get Variables:</p> <pre><code>&lt;script type="text/javascript"&gt; getSelectedOptionValue() { // create some variables to store your know values such as URL path and document var myPath = " put the URL path to the current document here "; var currentPage = "currentPage.php"; // get the values of any necessary select fields var carMake = document.getElementById("carMake").value; // write out the final URL with the Get Method variables you want using concatnitation var getMethodURL = myPath + currentPage + "?carMake='" + carMake + "'"; // function refreshes page using the function made URL window.location.replace( getMethodURL ); } &lt;/script&gt; </code></pre> <p>Since the second select field is dependent on the first you have to assume that the user is going to make a selection from the first choice of options. This means that the function that retrieves the value of the primary select field must run in response to a change in the fields selection. For example</p> <pre><code>&lt;select name="carMake" id="carMake" onchange="getSelectedOptionValue();"&gt; </code></pre> <p>Depending on how you have set up your DB, you may want either the value of the option tag or the string presented to the user between the option tags...this is up to you keeping in mind how you may re-query the information if your original record set hasn't already pulled up the necessary info to write the second set of select option tags.</p> <p>To write out the second select field using php simply repeat the while loop you have used for the first. This time replace your SQL statement with a new one using a variable in which you have stored the value retrieved from the new URL using the get method</p> <pre><code>&lt;?php // here I am using the more generic request method although you could use the get as well $carMake = $_REQUEST['carMake']; sql_secondSelectField = "SELECT * FROM tbl_carModels WHERE carMake = $carMake"; // Run new query and repeat similar while loop used to write your first select field ?&gt; </code></pre>
 

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