jQuery for dynamic forms - Review request

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

jQuery for dynamic forms - Review request

Post by $var »

Hello,
I am running into an issue that makes me think there is a better way to do things. Basically, it's a booking system that has many options pending on what was selected in each form section.

How I'm doing it:

- Form has a dropdown, it has 3 entries the correspond to hidden divs
- An option is selected and jQuery unhides the corresponding div
- Now, a Second dropdown is visible with 5 entries populated by PHP

That's where I stop. The second drop-down should allow the user to select an option and then populate ANOTHER drop down.
But, it's getting to the point where I would have about 100 hidden divs with custom PHP calls to get the right data into them.

I WANT to use the javascript variable to make my php call. But, in my understanding... never the two shall meet.
Is there a better way to do this?
User avatar
sergio-pro
Forum Commoner
Posts: 88
Joined: Sat Dec 27, 2008 12:26 pm

Re: jQuery for dynamic forms - Review request

Post by sergio-pro »

Hi

Personally I would append each new selection to existing container.
e.g. you have

Code: Select all

<div id="holder">
  <select onchange="loaddata()">...</select>
</div>
Then in load data you load required div from php and append it to holder div.
Within the data that came from server there should be next select, that will have its own onchange, that will load and append its own data and so on...
So after first call your page may look like:

Code: Select all

<div id="holder">
  <select onchange="loaddata()">...</select>
  <div>
    Loaded data
  </div>
  <select onchange="loaddata2()">...</select>
</div>
Post Reply