smproph Posted December 22, 2010 Share Posted December 22, 2010 I am working on a web app, here's the page I am on : http://sa.uintramural.com/autoselect/timeslip.php The fields choices are being pulled from a database. What I am trying to do is when someone types in a name and selects that person that it would look in the table for the 'Terms' and pull whatever value there is for that person and choose it automatically in the drop down menu. Could you point me in the right direction to do that or show me a code snippet. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/222397-auto-populate-field/ Share on other sites More sharing options...
MMDE Posted December 22, 2010 Share Posted December 22, 2010 If you don't want to do a refresh of the entire page, then I'd say you should look into AJAX! Quote Link to comment https://forums.phpfreaks.com/topic/222397-auto-populate-field/#findComment-1150372 Share on other sites More sharing options...
nafetski Posted December 22, 2010 Share Posted December 22, 2010 Ajax will be a clean way of doing it, but depending on your skill level you might want to keep it bread & butter php. Nothing would stop you from doing a page refresh on search, and displaying the results that way. Tho if you ARE going the ajax route, jQuery UI's autocomplete widget rocks Quote Link to comment https://forums.phpfreaks.com/topic/222397-auto-populate-field/#findComment-1150375 Share on other sites More sharing options...
smproph Posted December 22, 2010 Author Share Posted December 22, 2010 I'm not very advanced. While I know how to get around and change code to fit my needs, I'm not very good at writing, unless it's fairly simple. If I wanted to do it the php way, because I was looking at AJAX and I'm not sure if I could write something to do it, where would I start. Would I need it to autorefresh when user clicks on a name and then have it save that name in a variable and then just set the drop down default value as that variable? Quote Link to comment https://forums.phpfreaks.com/topic/222397-auto-populate-field/#findComment-1150386 Share on other sites More sharing options...
msaz87 Posted December 22, 2010 Share Posted December 22, 2010 I'm not very advanced. While I know how to get around and change code to fit my needs, I'm not very good at writing, unless it's fairly simple. If I wanted to do it the php way, because I was looking at AJAX and I'm not sure if I could write something to do it, where would I start. Would I need it to autorefresh when user clicks on a name and then have it save that name in a variable and then just set the drop down default value as that variable? If you want to do it strictly via php, then you could have the form look something like this: <?php $people_query = mysql_query("SELECT * FROM people") or die(mysql_error()); if(!empty($_REQUEST['person'])) { $terms_query = mysql_query("SELECT * FROM terms WHERE person = '".$_REQUEST['person']."'") or die(mysql_error()); while($row = mysql_fetch_array($terms_query)) { $terms = $row['terms']; } } ?> <form method="post" action="mypage.php"> Select a person:<br/> <select name="person"> <?php while($row = mysql_fetch_array($people_query)) { ?> <option><?php echo $row['name'] ?></option> <?php } ?> </select><br/><br/> <?php if(!empty($_REQUEST['person'])) { ?> Terms: <?php echo $terms ?><br/><br/> <?php } ?> <input type="submit" value="go"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/222397-auto-populate-field/#findComment-1150473 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.