Paul Smith Paul Smith - 1 year ago 66
jQuery Question

populate dropdown using jquery

I am trying to populate a drop down using JQuery but failing as I normally do, I can get the data to display in a Div but not in a drop down

I have a select id of name-data here is the JQuery code, what am I doing worng guys?

$('input#namein').on('change', function(){

var name = $('input#namein').val();
if ($.trim(name) != '') {
$.post('ajax/name.php', {name: name}, success = function(data) {

var options = "";

for(var i = 0; i < data.length; i++)
options += "<option value='" + data[i].toLowerCase() + "'>" + data[i] + "</option>";






Service user time Slots:
<input type="text" id="namein" value="Name">
Time Slots:
<form action="times" method="">
<select id="name-data"></select>
<script src="js/jquery-1.12.4.min.js"></script>
<script src="js/golabl1.js"></script>

Answer Source

Cheers Guys go it, I used

$( document ).ready(function() {

console.log( "ready!" );

        $.post('ajax/name1.php', success = function(data) {
                if (data != ''){