Page 1 of 1

autofull in textbox and dropdown menu

Posted: Thu Apr 27, 2006 11:37 am
by afma_afma
hello there,
i am a newbie and right now i am struck in one of the things i am learning.the problem is as follows:
i have two text boxes....student name and address.When i enter first two or three alphabets into my student name textbox,i shud get a drop down list having all possible names with the first two letters from database.then i see thro them and select the student name that i want to fill in.when i select the respective student name...the respective student address details must also come from the databse to the second textbox.....

please help me out...
thanx in advance...
ahmed

Posted: Thu Apr 27, 2006 12:51 pm
by GM
You will need to use Javascript here if you don't want to refresh the page.

If you really don't want the page to be refreshed, you need to "pre-load" everything to the page first, and use Javascript to fill in the Address when the name has been selected. Note that this means every single name, and its associated address will have to be pulled from the database while the pag loads - this could be VERY slow.

As for entering the first two or three letters of the person's name and having a list appear... I don't think this is possible. Depending on how much data you've got in your database, you could load all possible names into a Select field, but this will severely impact performance for anything other than a small dataset.

You could do it like this:

User enters first few letters of name, clicks button.
Form is submitted (therefore page is refreshed).
Database is queried, returning all people whose names begin with those letters, and their addresses.
Page reloads, with Select field containing names beginning with those letters.
OnChange event of the Select field can be used to fill in the Address field.

Edit: Just another thought - if the dataset is large, you'll probably want the user to enter at least 3 or 4 letters of the name before they click the button.

Posted: Thu Apr 27, 2006 1:31 pm
by Nathaniel
Yo, GM is somewhat correct - except nowadays you could use AJAX to accomplish what you want without having to load the entire dataset into one page.

Posted: Thu Apr 27, 2006 1:46 pm
by GM
Yup, agreed. I was trying to suggest a solution that requires just a basic knowledge of PHP and Javascript.