Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would use a jQuery load function. This is the simplest example I can muster up for you.</p> <p>You will need to download jQuery (<a href="http://docs.jquery.com/Downloading_jQuery" rel="nofollow">http://docs.jquery.com/Downloading_jQuery</a>) and include it in your html header:</p> <pre><code>&lt;script type="text/javascript" src="js/jquery-1.4.2.min.js"&gt;&lt;/script&gt; </code></pre> <p>Then you can make a simple function to call; either as a onclick or onchange depending on your preference.</p> <pre><code>function reloadDropDown() { document.getElementById('dynamicInput').innerHTML = 'Loading ...'; var v_name = document.formname.elementname.value; $('#dynamicInput').load("dropdownload.php", { vehicle_name : v_name }); } </code></pre> <p>Let me go through this. dropdownload.php would have your '$queryveh' made drop down code. Javascript basically plonks whatever happens in dropdownload.php on to a div with the id 'dynamicInput' When javascript loads dropdownload.php it sends via POST a variable by the name vehicle_name which you can use as $_POST['vehicle_name'] within dropdownload.php.</p> <p>So, dropdownload.php may look something like this.</p> <pre><code>&lt;?php $queryveh = mysql_query("SELECT * FROM vehicletbl WHERE vehname = '{$_POST['vehicle_name']}'"); // collect the data and put it in to an Array I like to do this so I can check the array to make sure it has something in it if not return an error message but I will skip that for the purpose of this explanation. while($ucRow = mysql_fetch_array($queryveh, MYSQL_ASSOC)) array_push($resultsArray, $ucRow); ?&gt; &lt;select name = "vehicle[]" id = "vehicle1"&gt; &lt;?php foreach ($resultsArray as $fetch_row){ ?&gt; &lt;option value = "&lt;?php echo $fetch_row['vehbrand'].' '.$fetch_row['vehname'].'; ?&gt;"&gt;&lt;?php echo $fetch_row['vehbrand'].' '.$fetch_row['vehname']; ?&gt;&lt;/option&gt; &lt;?php } ?&gt; &lt;/select&gt; ?&gt; </code></pre> <p>I'm not entirely certain on the end result you are after but that is a basic jQuery ajax call. If you can grasp that, you are half way to a truly dynamic web page / app with some further practice with this area. Hope that gives you a direction to go in :)</p>
 

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