Dynamic Drop Down Form Field
03-07-2010, 07:28 PM
|
Dynamic Drop Down Form Field
|
Posts: 102
|
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...
|
|
|
|
03-07-2010, 08:12 PM
|
Re: Dynamic Drop Down Form Field
|
Posts: 115
Name: Chris Duerr
|
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 
|
|
|
|
03-07-2010, 10:32 PM
|
Re: Dynamic Drop Down Form Field
|
Posts: 102
|
How would I use ajax to update the html on the page? Not too familiar with ajax...
|
|
|
|
03-08-2010, 04:13 PM
|
Re: Dynamic Drop Down Form Field
|
Posts: 102
|
Is there any other way to pull this off?
|
|
|
|
03-08-2010, 04:20 PM
|
Re: Dynamic Drop Down Form Field
|
Posts: 102
|
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..
|
|
|
|
03-09-2010, 03:44 PM
|
Re: Dynamic Drop Down Form Field
|
Posts: 102
|
Is there no easy way to pull this off? Really need help with this if possible...
|
|
|
|
03-09-2010, 04:53 PM
|
Re: Dynamic Drop Down Form Field
|
Posts: 102
|
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...
|
|
|
|
|
« Reply to Dynamic Drop Down Form Field
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
|