Thanks Raja. That worked! For reference, I also needed to put something in place to wait until the .trigger('refreshOpts'); call had completed. The use of animate() as a sort of sleep routine is a bit of a kludge, since it seems .trigger() doesn't implement a callback, so I wound up with this:
$("#addRefForm").submit(function() { var author = $("#author").val() var detail = $("#detail").val() var refYear = $("#refYear").val() var refType = $("#refType option:selected").val() var newReference = 1 $.post('index.cfm?view=saveReferenceFromPopup', { author:author, detail:detail, refYear:refYear, refType:refType, newReference:newReference }, function(data,status) { // console.log(status) if(status == 'success'){ $("#refSelectBox").trigger('refreshOpts'); $("#refSelectBox").animate({opacity: 1.0}, 950, function(){ $("#refSelectBox option:selected").removeAttr("selected"); $("#refSelectBox option[text^=" + author + "]").attr ("selected","selected"); }); } } ); On Apr 17, 2:40 pm, Raja Koduru <kscr...@gmail.com> wrote: > $("#refSelectBox option[text^=" + author + "]").attr("selected","selected"); > > I guess the above is doable. > let me know. > > - raja koduru > > On Thu, Apr 16, 2009 at 11:16 PM,Nando<d.na...@gmail.com> wrote: > > > I'd like set a newly inserted option in a select box as the selected > > option. I'm trying to use jQuery to select the option using the option > > text, which begins with the author name as defined in the function. > > > In the examples I've found, $("#refSelectBox option[text^=author]") > > would presumably select any option that begins with the literal > > "author", but I need it evaluated instead. > > > Given the following ... > > > $("#addRefForm").submit(function() { > > var author = $("#author").val() > > var detail = $("#detail").val() > > var refYear = $("#refYear").val() > > var refType = $("#refType option:selected").val() > > var newReference = 1 > > $.post('index.cfm?view=saveReferenceFromPopup', { > > author:author, > > detail:detail, > > refYear:refYear, > > refType:refType, > > newReference:newReference > > }, function(data,status) { > > if(status == 'success'){ > > > > $("#refSelectBox").trigger('refreshOpts'); > > $("#refSelectBox > > option[text^=author]").attr > > ("selected","selected"); > > } > > } > > ); > > > $('#dialog').dialog('close'); > > return false; > > }); > > > ... how to select the newly inserted option in #refSelectBox using the > > text attribute and set it to the selected option? > > > Any alternate suggestions are most welcome! > > > Thanks, > >Nando