daled Posted August 19, 2007 Share Posted August 19, 2007 is there a way to populate a second select field in a form based on input for a first select without reloading and using only php? Filter Reports Where: <select name='filterby'> <option value='date'>Date</option> <option value='offender'>Offender</option> <option value='by'>Reported By</option> </select>"; is: <select name='field'><option value=""></option></select> </form><br> What I want to happen is when the first changes, the second pulls possible choices from the database corresponding to what was chosen. I tried using a function and calling upon it the same way you would javascript with an "onchange" in the first select: <select name='filterby' onchange='populate_second'> <?php function populate_second($filterby) { $conn = mysql_connect('localhost', 'root', ''); mysql_select_db('masterdatabase', $conn); $query_field = "SELECT `".$filterby."` FROM `reports` WHERE `type` = '".$_GET['action']."'"; $field = mysql_query($query_field, $conn); $row_field = mysql_fetch_assoc($field); }; ?> is there something wrong with the function, the way i'm calling upon it, or is it something that just can't be done? thanks if you can help! Quote Link to comment https://forums.phpfreaks.com/topic/65738-solved-populating-a-second-select-field/ Share on other sites More sharing options...
trq Posted August 19, 2007 Share Posted August 19, 2007 is there a way to populate a second select field in a form based on input for a first select without reloading and using only php? Nope. PHP runs on the server so you must make a request to the server to use it. What your trying to do is best achieved with Javascript, or if you really need database interaction, Ajax. Quote Link to comment https://forums.phpfreaks.com/topic/65738-solved-populating-a-second-select-field/#findComment-328386 Share on other sites More sharing options...
MadTechie Posted August 19, 2007 Share Posted August 19, 2007 Echo thorpe. perfect reply! google "php dynamic drop down" Quote Link to comment https://forums.phpfreaks.com/topic/65738-solved-populating-a-second-select-field/#findComment-328387 Share on other sites More sharing options...
daled Posted August 20, 2007 Author Share Posted August 20, 2007 i figured out that iframes will do it well enough. Quote Link to comment https://forums.phpfreaks.com/topic/65738-solved-populating-a-second-select-field/#findComment-328815 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.