I need to create options of a select element dynamically via an ajax call. The number of options and their content will vary. This is how it looks prior to the ajax call:
<select name="groupid" style="width:100%;">
<option value="0" selected>(Please select an option)</option>
</select>
Here is one of my attempts to create an option element with a dummy value:
$("<option></option>", {value: "999"}).appendTo('.select-group');
But it adds it outside of select. I also don't know how to set the text within .
Any ideas? I've seen some questions about populating existing select forms with a static number of existing options but not one like this.
Thanks.
'.select-group'is yourselectelement, then it will work, though you probably want to give it some text too:{value: "999", text: "999"}.