This turned out to be the solution................ var drp = $('#dropdown'); drp.children().each(function() { $(this).removeAttr("selected"); }).end().append("<option value='"+insertid+"' selected='selected'>"+project+"</option>");
I am sure jselect would have worked too (possibly a bit of an overkill?), so thanks to RvFlash On Apr 4, 10:31 am, LinkGuru <i...@legalanalytics.co.uk> wrote: > Thanks RvFlash, I'll take a look. I just missed your post before I > sent my chase up message. > > On Apr 4, 10:29 am, LinkGuru <i...@legalanalytics.co.uk> wrote: > > > Can anyone help with this? It appears to have been overlooked. The > > title should really have been "changing the selected item in a > > dropdown" (perhaps) because I know how to do the append, I just can't > > get my head around how to modify the existing items in the list. Will > > it be easier to rebuild the list? > > > On Apr 3, 6:22 pm, LinkGuru <i...@legalanalytics.co.uk> wrote: > > > > 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("<optionvalue='"+insertid+"' > > > selected='selected'>"+project+"</option>"); > > > }); > > > } > > > ); > > > //Thanks in advance.