Form with Ajax / Json / PHP

0

Alright? could they help me with the following problem.

I see several people talking about creating forms with Json / Ajax and everything, but like, I'm way out of this still.

But I had the need to prepare a form as follows.

The form would have 2 combobox (dropdown)

  • 1st Combobox: OPTION 1, OPTION 2

and a second combobox that would be populated according to the first combobox.

If the 1st combobox is OPTION 1, then the second combobox would load the item "SERVICO1", if the combobox is OPTION 2, then the second combobox would load the item "SERVICE2".

Someone could help me, I promise that I will only use it as a study.

    
asked by anonymous 23.10.2016 / 01:11

1 answer

0

Thiago, your question is not very clear. You have put Ajax / Json / PHP in the title, but if I understand correctly, it does not seem to need any of this.

I'll describe the most common scenarios and you'll see which fits best.

In all cases, you will need a function whose trigger will be the change event of the first Select.

Scenario 1: When you load your form, you already have the first and second Select data.

When the first select was changed, its function will check the selected option and set the value of the second Select.

Scenario 2: When you load your form, you have the data of the first Select, but the data of the second depends on the option chosen in the first one.

Here you have 2 possible solutions:

  • Load two sets of options for the second Select and, in your function that captures the change event, you define the set of options for the second Select.
  • Load only the first Select options. In the change event, its function makes an Ajax that loads the options and mount the second Select.
  • These are the most common scenarios I see happening. If you can better specify your situation, I can go into more detail.

        
    24.10.2016 / 17:35