Not sure if theis is the write room, but i though would be the best place to start..

Im building a site for my mate, currently testing on

now im trying to find a script that will pull data from a drop down selection either via a CSV file or a DB.

similar to whats on theis site...

problem is i dunno what im searching for.

THanks for your help

Billie

Dani AI

Generated

As is building a directory-style site and wants dropdown options from a CSV or DB, the most maintainable pattern is: keep data on the server (prefer a DB for dynamic lists), expose a simple endpoint that returns JSON, and populate the <select> on the client. A DB avoids manual exports and concurrency issues; CSV is only practical for small, rarely changed lists. As noted, client-side libraries can help; as suggested, server-side storage is the right direction.

A minimal client-side workflow (using Fetch) looks like this:

fetch('/api/locations')
  .then(r => r.json())
  .then(items => {
    const sel = document.getElementById('locationSelect');
    sel.innerHTML = '<option value="">Choose...</option>';
    items.forEach(it => {
      const opt = document.createElement('option');
      opt.value = it.id;
      opt.textContent = it.name;
      sel.appendChild(opt);
    });
  })
  .catch(err => console.error(err));

If the site already uses jQuery (see ), $.getJSON() is a simple alternative. Important operational notes: return Content-Type: application/json; charset=utf-8, handle CORS if the API is on another host, escape/validate server data, and paginate or use typeahead for very large lists instead of loading thousands of options. For keyboard and screen-reader users, label the control and consider grouping with <optgroup> or using an accessible autocomplete pattern. For Fetch and JSON details see Using Fetch and JSON basics; accessibility guidance for form controls is at WebAIM - Form Controls.

Recommended Answers

All 2 Replies

You can try JQuery fot that :)

Hi billie,

Ok, So I would go mySQL (instead of CSV) simply because we can pull it straight from the db without having to manually get involved (yes, in most CSV cases, exporting is a MUST).

Here's a link that should cover everything;
Dynamic Drop down

All the best

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.