[jQuery] appending an option to select list (dropdown), making it the selected one
With the following code, I'm managing to append to a drop-down list
using jQuery, but can't figure out how to amend one of the existing
items in the drop down so it is not the selected one i.e. I only want
the one that's appended to be the selected one.
Can anyone help?
Here is the simplified code.
$(".actionOptAdd").bind("click",
function()
{
.
.
.
$.getJSON('lib/addToProj.php',
{....}, function(data)
}, function(data)
{
$.each(data, function(i,item)
{
if ( i == "project" )project=item;
if ( i == "insertid" )insertid=item;
});
var drp = $('#dropdown');
drp.append("<option value='"+insertid+"'
selected='selected'>"+project+"</option>");
});
}
);
//Thanks in advance.