Form with Ajax / Json / PHP

Asked

Viewed 221 times

0

all right ? could you help me with the following problem.

I see a lot of people talking about creating Formulars with Json / Ajax and all that, but like, I’m pretty much on the outside of it yet.

But I came to the need to draw up a form as follows.

The form would have 2 combobox ( dropdown )

  • 1st Combobox : OPTION 1 , OPTION 2

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

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

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

  • Which code is trying and which point is finding difficulty ?

1 answer

0

Thiago, your question is not very clear. You put Ajax / Json / PHP in the title, but, if I understand correctly, it seems that you do not need any of this.

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

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

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

When the first select has been changed, its function will check the selected option and sets 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.

Here you have 2 possible solutions:

  1. Load two sets of options for the second Select and, in your function that captures the event change, you define the set of options for the second Select.
  2. Load only the first Select options. At the event change, its function makes an Ajax that loads the options and mounts the second Select.

These are the most common scenarios I see happening. If I can specify your situation better, I can detail more.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.