-1

I would like to create a select with options dynamically at the starting page on function document.ready.

Can i to do that?

I try, but it doesn't works.

 $('#form').append('<select id="myselect" name="myselect">/select>');
    $('#myselect').append('<option  title="#" value="">GREEN</option>');

Thank you.

lebossejames
  • 23
  • 1
  • 8

3 Answers3

1

Try this : wrap your code inside document.ready and append select tag to form. Please make sure that select and option tag closed properly.

$(document).ready(function(){
$('#form').append('<select id="myselect" name="myselect"><option  title="#" value="">GREEN</option></select>');
});
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
0

Programmatically create select list

This should be a better way to create the select, then you can do:

$('#form').append(sel);
Community
  • 1
  • 1
Soulan
  • 341
  • 1
  • 6
0

There is an error with your closing html tag of select element in jquery. Also try to use appendTo like,

$('<select id="myselect" name="myselect"></select>').appendTo('#form')
   //--- also check the closing html tag ^-- is proper
    .append('<option  title="#" value="">GREEN</option>');

Or you can use it in a single call like

var myselect='<select id="myselect" name="myselect">' +
                '<option  title="#" value="">GREEN</option>' +
             '</select>';
$('#form').append(myselect);
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106