Jump to content

Auto populate field


smproph

Recommended Posts

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.