autofull in textbox and dropdown menu

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
afma_afma
Forum Newbie
Posts: 2
Joined: Tue Mar 28, 2006 11:24 am

autofull in textbox and dropdown menu

Post 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
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post 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.
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post 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.
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

Yup, agreed. I was trying to suggest a solution that requires just a basic knowledge of PHP and Javascript.
Post Reply