PHP forums, MySQL forums, Web Development resources

Home PageHome    PHP ResourcesTopic List    FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups 
 RegisterRegister
    ProfileProfile    Log in to check your private messagesLog in to check your private messages    Download the RSS Reader RSS Feed Download the RSS Reader RSS for this forum Log inLog in 

PHP Forum :: MySQL Forum :: Java Script Forum



Dynamically creating form fields based on user selection

 
Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General
View previous topic :: View next topic  
Author Message
mmathis



Joined: 25 Mar 2008
Posts: 8

PostPosted: Tue Mar 25, 2008 4:31 am    Post subject: Dynamically creating form fields based on user selection Reply with quote

I have a form with 3 fields. I want the third fields options to be based on what the user chose in the second form field. If the user chooses "income" in the second field then certain values appear as choices in the 3rd field. If the user chooses "expenses" in the second field, then different values appear as choices in the third field.

I've attached my code snippet. I'm not sure where to put the code for the third field. Should I put it in the display block after the $option_block2 select statement?

How would I reference the choice the user made in the second field? For some reason I seem to remember a way to do this using javascript but honestly dont recall.
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 4958
Location: toronto, canada

PostPosted: Wed Mar 26, 2008 3:58 am    Post subject: Reply with quote

http://www.dynamicdrive.com/dynamicindex16/chainedselects/chainedselects.html may be of use to you
_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
mmathis



Joined: 25 Mar 2008
Posts: 8

PostPosted: Wed Mar 26, 2008 4:17 pm    Post subject: Reply with quote

This requires that you manually list each combination. I want to extract it from a mysql database. Ive found one but am having trouble configuring it for the second table.

The URL is http://www.phpclasses.org/browse/package/2289.html

It works with his simple tables. My first table is called types (ironically) has 2 fields, accountID and account_desc. I substituted type_id for accountID. My second table is called types_category and has a primary key made up of its only 2 fields, type and category. This is where I think my translation is in error. I changed type_id to type in the brand section (line 98 of the class). My third table is called cat_sub and has 3 fields, cat_subID whch is autoincrement, category and subcategory. Here I changed brand_id to category in the model section (line 108 of the class). His logic is that the brand_id is autoincrement so I'm not sure how he's matching them up.

Can you help me?
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 4958
Location: toronto, canada

PostPosted: Thu Mar 27, 2008 3:15 am    Post subject: Reply with quote

No, it requires that each option choice becomes an array in the js, you can write out the values to the js array with php...thats what i did
_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
mmathis



Joined: 25 Mar 2008
Posts: 8

PostPosted: Thu Mar 27, 2008 4:15 am    Post subject: Extract from db Reply with quote

what lines actually extract it from a database? I went through the code but didn't see this.
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 4958
Location: toronto, canada

PostPosted: Thu Mar 27, 2008 5:19 am    Post subject: Reply with quote

It doesn't, you need to work that out
_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Display posts from previous:   
WeberTrivia Questions WeberTrivia Questions
 Think you are smart? Prove it!. Try your skills with these questions :
 WeberTrivia QuestionsRecursive arrays and multi-dimensional arrays are one and the same. (PHP and MySQL)
 WeberTrivia QuestionsThe \"cache_dir\" tag of the squid configuration has a default of /var/spool/squid. (Linux)

WeberTrivia Questions



PHP Code Examples
 Stream diffrent sizes of images from a single image to save disk space.
 JavaScript dropdown list menu to switch any page.
 Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
 PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside.
 Link Extractor - This function is used to extract links from a given URL. This will convert relative path into absolute path and also remove PHPSESSID stuff.
 Building a Dynamic Form using Javascript and innerHTML. Add form elements in realtime without refreshing the page.
 A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Post new topic   Reply to topic    WeberForums.com Forum Index -> PHP General All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum






Powered by phpBB © 2001, 2005 phpBB Group
PHP Forum :: MySQL Forum :: Java Script Forum