Skip to content

Populate an HTML DropDown List with data from mysql database without PHP

I’m currently building a rails app where im trying to fetch data from different tables from my sql database and I need to put that fetched data (id, first_name, last_name) into an HTML Drop-down where the user is going to select between all possible choices, for exemple:


default: –SELECT–

1 Thomas Carrier

2 Michel Carrier

3 Yvon Dupuis

So if we take the first choice, 1 is the id of the first employee, and his first name (Thomas) and last name (Carrier)

I keep finding stuff about php but I cannot use php!

Thanks for the help



The easy answer

plain html

<select name="clients">
    <option value="1">Thomas Carrier</option>
    <option value="2">Michel Carrier</option>

or with ruby (

<select name="clients">
    <% @clients.each do |client| %>
        <option value="<%= %>"><%= client.firstName %> <%= client.lastName %></option>
    <% end %>

Also refer to Yaniv Iny’s answer to for a better more correct way

3 People found this is helpful