Aisha
Aisha

Reputation: 11

Populating listbox with a function that gets values from a table

I have 2 listboxes on my web page. I want to populate second listbox by a value selected in first list box. When I select an option in firstlistbox it queries a table on my backend and populates the secondlist box based on the results. I cannot use php script inside a javasript so what should I do?

Upvotes: 0

Views: 103

Answers (1)

Shalitha Suranga
Shalitha Suranga

Reputation: 1146

You are asking how create a sub categories list box. You need create it easily using AJAX.

Here are the steps you need to do.

  1. Populate first list box and call function loadData() when you change item.
  2. send ajax request to getdata.php with selected category_Id parameter
  3. Make getdata.php to output second list box according to category_Id
  4. Display ajax response on page as html

I found this article for you.

Hope it helps.

Upvotes: 0

Related Questions