JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 23rd, 2004, 04:07 AM
abrahamsony abrahamsony is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 abrahamsony User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy PHP and Javascript

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.

Reply With Quote
  #2  
Old February 23rd, 2004, 11:04 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to dhouston
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.

Reply With Quote
  #3  
Old February 23rd, 2004, 08:06 PM
abrahamsony abrahamsony is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 abrahamsony User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

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?

Reply With Quote
  #4  
Old February 23rd, 2004, 09:39 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Posts: 2,056 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 44 m 22 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > PHP and Javascript


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap