|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
I have a page with a combo box containing the names of some people. In the same page there are some textboxes in which the data like address, phone no, e-mail id etc of the people is to be displayed.
My requirement is like when an user selects a name in the combo box the corresponding information of the name selected should get filled in the textboxes in the same page. It should happen as soon as the item in the combo box is changed ie, using the OnChange fn. of combo box. Please help me with a simple code snippet as i'm a beginner in web programming. I'm using PHP for server and MySQL as database. |
|
#2
|
||||
|
||||
|
You'll need to use PHP to generate a bunch of javascript variables or arrays containing the information in question. The select box invokes a function that inserts the appropriate array values into the text fields. This will scale only so far. If you've got hundreds of names, you'll need to consider taking a different tack, such as having onchange submit the form, which reloads with the other info filled out for the person whose name was selected.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#3
|
|||
|
|||
|
As you said i'm submitting the form as soon as the item changes. In the action of the form i'm writing the name of the php file in which the code forloading is written like
File - index.php <FORM NAME="combo" METHOD="POST" ACTION="fetch.php"> <SELECT name="personid" ... onChange="this.form.submit();"> <OPTION value="">-- select Person --</OPTION> <OPTION value="id1">Person 1</OPTION> <OPTION value="id1">Person 1</OPTION> <OPTION value="id1">Person 1</OPTION> </SELECT> </FORM> I need to fetch the data from database corresponding to the item currently selected in combobox. How can i pass the index of that item to php page? Also after fetching the data using fetch.php i need to display the contents in index.php. I need to set the item selected by user to be selected in the first combo and the corresponding data to be filled in the textboxex of index.php how can i transfer that data back to javascript in index.php from fetch.php? |
|
#4
|
||||
|
||||
|
Just request the value of the SELECT object (personid, in your case) in your PHP after submitting the form, as only the selected item is returned.
To have a particular person selected when the page is loaded, simply select that person (using the "selected" keyword), when building your SELECT list after pulling out their details from the DB. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > PHP and Javascript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|