dbzz wrote:
> 
> 
>>> We need to make a list of "stupid problem areas in
>>> JavaScript/HTML/CSS". We can then check off the ones that we've solved
>>> (such as appending HTML <tr>..</tr> to a table) and ones that we
>>> haven't (animating the height of table rows, appending  HTML <option>
>>> to a <select>, etc.). In fact, here's a wiki page for it:
>>> http://jquery.com/docs/HardProblems/
>> Ohhh ... I've been wanting to solve that IE options issue for a while
>> now. So much fun and so little time. :)
>>
>>> Let's flush this out!
>> --
>> Brandon Aaron
>>
>>
> 
> i ran into that 'options as html failure in ie' recently and found i could
> add them 
> to a temp select, append that to the document, and then appendTo the
> original select. 
> i imagine there's some nicer code to do this with, but here's what worked
> for me:
> (only tested in ie6 and ff1.5 on xp)
> 
> $.fn.addoptionhtml = function(str){
>       str = '<select id="tempselect">' + str + '</select>'
>       $(this).append(str);
>       $('#tempselect')[0] = new Option($(str).find('option'));
>       $('#tempselect option').appendTo(this);
>       $('#tempselect').remove();
> }
> 
> $("#myselect").addoptionhtml('<option value="1">one</option><option
> value="2">two</option>')

I use this in a loop, and it's not working well in FF 1.5, the second
option couldn't clicked. I use this simple hack:

//in a loop
  var value = someval;
  var label = somelabel;

  if (document.all) {//if IE
    $("#myselect").addoptionhtml('<option
value="'+value+'">'+label+'</option>');
  } else {// non-IE
    $("#myselect").append(new Option(label, value));
  }

//after end of loop
//because in IE, it select the last options
$("#myselect").children().eq(0).attr('selected',1); //this code fail in
Opera9

The above code tested in FF1.5, IE6, and Opera9 in WinXP SP2

--
Donny Kurnia
http://hantulab.blogspot.com
http://hantulab.multiply.com


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to