Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Dynamic Drop Down Form Field
Old 03-07-2010, 07:28 PM Dynamic Drop Down Form Field
Jasonpv's Avatar
Super Talker

Posts: 102
Trades: 0
Hello, I am trying to create a form that needs to change based on a user's birthdate. Basically, if they select a year of birth within a certain range I need to have the next drop down change depending on the year of birth selected. I have a rough idea of how I need to do this so here goes. I am assuming I need to use some basic javascript to have the page reload once the date of birth is selected. I then need to set a php variable that represents the date of birth the user selected which then gets used to determine which version of the next drop down I want put on the page. Is this the correct way of going about doind this? Any help is greatly appreciated as always...
Jasonpv is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-07-2010, 08:12 PM Re: Dynamic Drop Down Form Field
addonchat's Avatar
Super Talker

Posts: 115
Name: Chris Duerr
Trades: 0
If the program logic is simple, the associated data sets to the birth year are small, there is no concern about the ease of the data being stolen and the associated, then do it all in JavaScript.

Otherwise your logic is correct, though I would advise against page reloads. Use AJAX. Let JavaScript make a call to your PHP script which will spit out the data associated with the year (XML, JSON, ...), load in the data and perform the necessary DOM updates.

It's a fair amount of work for a single page if you don't already have a nice API, but well worth the effort from the end-user's point of view.

My two cents
__________________
Chris Duerr
AddonChat Java Chat Software

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
addonchat is offline
Reply With Quote
View Public Profile
 
Old 03-07-2010, 10:32 PM Re: Dynamic Drop Down Form Field
Jasonpv's Avatar
Super Talker

Posts: 102
Trades: 0
How would I use ajax to update the html on the page? Not too familiar with ajax...
Jasonpv is offline
Reply With Quote
View Public Profile
 
Old 03-08-2010, 04:13 PM Re: Dynamic Drop Down Form Field
Jasonpv's Avatar
Super Talker

Posts: 102
Trades: 0
Is there any other way to pull this off?
Jasonpv is offline
Reply With Quote
View Public Profile
 
Old 03-08-2010, 04:20 PM Re: Dynamic Drop Down Form Field
Jasonpv's Avatar
Super Talker

Posts: 102
Trades: 0
Here is the dropdown that I would like to change. If they select a birth year from 1970 - 1961 then I want the first 2 options to not show. Otherwise the full list should show.

Code:
<select name="coverage_amt" id="coverage_amt" class="form_fields" style="width: 140px">         
    <option value="$100,000">$100,000</option>
    <option value="$200,000">$200,000</option>
    <option value="$250,000" selected="selected">$250,000</option>
    <option value="$300,000">$300,000</option>
    <option value="$400,000">$400,000</option>
    <option value="$500,000">$500,000</option>
    <option value="$600,000">$600,000</option>
    <option value="$700,000">$700,000</option>
    <option value="$800,000">$800,000</option>
    <option value="$900,000">$900,000</option>
    <option value="$1,000,000">$1,000,000</option>
    <option value="$1,500,000">$1,500,000</option>
    <option value="$2,000,000">$2,000,000</option>
    <option value="$3,000,000">$3,000,000</option>
    <option value="$4,000,00">$4,000,000</option>
    <option value="$5,000,000">$5,000,000</option>
    <option value="$6,000,000">$6,000,000</option>
    <option value="$7,000,000">$7,000,000</option>
    <option value="$8,000,000">$8,000,000</option>
    <option value="$9,000,000">$9,000,000</option>
    <option value="$10,000,000">$10,000,000</option>
</select>

Last edited by Jasonpv; 03-08-2010 at 04:21 PM..
Jasonpv is offline
Reply With Quote
View Public Profile
 
Old 03-09-2010, 03:44 PM Re: Dynamic Drop Down Form Field
Jasonpv's Avatar
Super Talker

Posts: 102
Trades: 0
Is there no easy way to pull this off? Really need help with this if possible...
Jasonpv is offline
Reply With Quote
View Public Profile
 
Old 03-09-2010, 04:53 PM Re: Dynamic Drop Down Form Field
Jasonpv's Avatar
Super Talker

Posts: 102
Trades: 0
Ok, so I just ended up making the two versions of the drop down field in two different table rows. One is set to hidden by default and I use some javascript to set the other to show and the first to hidden if the year of birth matches. This may not be the best way of doing this but it seems to work as I wanted it. Only thing is this will fail if js is turned off on the client side...
Jasonpv is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Dynamic Drop Down Form Field
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.83731 seconds with 12 queries