I have a table containing name and address in mysql.I have a form in php which has a textbox where the user can enter the name and clicking the button gets the corresponding address from mysql database.Now I want to modify the script so that when the user is typing the name, the corresponding list of names starting with the letter/letters the user has typed so far should appear in the textbox as a list of alternatives from where the user can choose the name without typing further(Something similar to the phonebook of our mobile phones and something which the browser automaticaly does for the textbox by showing the previous inputs from the cache.).Please help.
How to create the mobile phone effect
You need to either load the whole address book and use javascript on the form and results, or use AJAX. I can't help on either sorry.
I mainly want to know if it is possible to fetch the information from mysql database by using focus/keypress event which requires the integration of javascript and php. Any help?
I'm not 100% sure how you would be able to do this but maybe using javascript you could anchor to a letter in the address book a javascript or ajax would allow you to do this.
Try this site, i think it might be what you're looking for:
- <a href="http://javascript.internet.com/navigation/key-launcher.html"> Click Here </a>
Louis.
Try this site, i think it might be what you're looking for:
- <a href="http://javascript.internet.com/navigation/key-launcher.html"> Click Here </a>
Louis.
I'm not going to explain everything, that would be too long, but some hints:
The client-side part:
Use onkeypress (or whatever Javascript event you prefer) to call a function.
The server-side part:
Make a PHP script that expects a POST parameter (like submitting a form, $_POST['...']) with the letters the user entered, that returns a list of names (can be returned as XML, or just plain text, separated by line breaks or anything you want).
The AJAX part, the integration:
Now the hardest part, programming the function called by onkeypress.
- First, get the letters inserted by the user.
- Next, post this data to the PHP page. To do this, take a look at XMLHttpRequest. Tutorial here, basic usage here.
- You will get the raw output of the PHP page, extract the names from it, and present them to the user in some fancy way.
The client-side part:
Use onkeypress (or whatever Javascript event you prefer) to call a function.
The server-side part:
Make a PHP script that expects a POST parameter (like submitting a form, $_POST['...']) with the letters the user entered, that returns a list of names (can be returned as XML, or just plain text, separated by line breaks or anything you want).
The AJAX part, the integration:
Now the hardest part, programming the function called by onkeypress.
- First, get the letters inserted by the user.
- Next, post this data to the PHP page. To do this, take a look at XMLHttpRequest. Tutorial here, basic usage here.
- You will get the raw output of the PHP page, extract the names from it, and present them to the user in some fancy way.
