Page 1 of 1

jQuery for dynamic forms - Review request

Posted: Mon Jan 10, 2011 2:03 pm
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?

Re: jQuery for dynamic forms - Review request

Posted: Thu Jan 13, 2011 3:11 am
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>