The javascript has to be in an external file. Both of these are similar to what I had done in other attempts. The odd thing is, in IE I can see the first element of the data has the 'selected' attribute, even though the original HTML sent by the server doesn't have it. The only thing I can figure is either IE is adding it via the underlying call from the $.get(), or jQuery itself is adding it.
I did come up with a less than elegant way of handling the problem: $.get("create.do", params, function(data) { var id = $(data).attr('id'); var idSel = '#'+id; // Faster than adding the '#' everywhere it is needed??? if( $('option', idSel).length > 0 ) { // Is the option tag present? $('option:not(:first)', idSel).remove(); // Clear out all option tags but the first. $(data).children().each(function() { // For each child, add a new option. $(idSel).append('<option value="' + $(this).val() + '">' + $ (this).text() + '</option>'); }); $(idSel).removeAttr('disabled'); // Enable the field. } } ); I have to call remove() because this code is called on blur, so just Alt-Tab'bing away from the browser added another set of entries. On Oct 15, 8:22 am, JohnieKarr <[EMAIL PROTECTED]> wrote: > I don't do this with client side, I do it with server side and a > database, but I think you should try one of the following: > > 1) > <label for="type" class="dialog first">Select Type</label> > <select id="type" class="dialog first"> > <option selected="selected" value="">--- Type ---</option> > <script type="text/javascript"> > // javascript here to dynamically load content > </script> > </select> > > or > 2) > <label for="type" class="dialog first">Select Type</label> > <select id="type" class="dialog first"> > //No option to start with > </select> > > javascript: > Then make your javascript add the first option. If it is the first in > the list then it will be selected by default so there is no need to > add selected="selected" > > Hope this helps, > Johnie Karr > > On Oct 14, 1:57 pm, TimW66 <[EMAIL PROTECTED]> wrote: > > > Anyone? > > > On Oct 13, 6:08 pm, TimW66 <[EMAIL PROTECTED]> wrote: > > > > I'm seeing some odd behavior in IE with my SELECT boxes. In the > > > static HTML, I have the following: > > > > <label for="type" class="dialog first">Select Type</label> > > > <select id="type" class="dialog first"> > > > <option selected value="">--- Type ---</option> > > > </select> > > > > In JavaScript, I have the following: > > > > $.get("create.do", params, > > > function(data) { > > > if( $('option', idSel).length > 0 ) { > > > var firstOption = $('option', idSel); > > > $(idSel).replaceWith(data); > > > $(idSel).prepend(firstOption); > > > $(idSel).removeAttr('disabled'); > > > } > > > } > > > ); > > > > The data coming back is actually a snippet of HTML, like this: > > > > <select id="type"><option value="1">In</option><option value="2">Out</ > > > option></select> > > > > Note it does not contain a "selected" attribute. What I want is to > > > merge the data with the static HTML so in essence I would have: > > > > <label for="type" class="dialog first">Select Type</label> > > > <select id="type" class="dialog first"> > > > <option selected value="">--- Type ---</option> > > > <option value="1">In</option> > > > <option value="2">Out</option> > > > </select> > > > > However, in IE, the "selected" attribute always seems to get set on > > > the "In" instead. > > > > Is this yet another odd thing with IE? Is there something else I > > > should be doing to get the desired results? > > > > Thanks in advance.- Hide quoted text - > > > - Show quoted text -