← Back to team overview

dhis2-devs team mailing list archive

Re: Minor javascript cross-browser hack

 

Hi,

If you want to use jQuery, I think the best way is create an array of string
then append them into the select tag

var options = [ ] ;

for( .. ) {
  options.push("<option value='$id'>$title</option>");    // collect items
}

jQuery("#selector").append(options.join(""));  // append a string into a
tag.



Regards,


2010/1/22 Lars Helge Øverland <larshelge@xxxxxxxxx>

>
>
> On Fri, Jan 22, 2010 at 12:16 PM, Viet Nguyen <phamquocviet@xxxxxxxxx>wrote:
>
>> Hi,
>>
>> Just a minor javascript cross-browser hack.
>>
>> When adding an options to a select tag using javascript, I can see in DHIS
>> you are doing like this :
>>
>>  optionComboSelector.add( option, null );
>>
>> This will only work on gecko-based browsers. For IE ( tested with IE 8  &
>> 7 ) it will throw error ,  the right one should be like this :
>>
>>  optionComboSelector.add( option ); // only one param
>>
>> So the solution should be :
>>
>>    try {
>>         optionComboSelector.add( option, null );  // for gecko-based
>> browser...not tested with other webkit-based browsers ...
>>     }catch(e){
>>         optionComboSelector.add(option);  // just for IE
>>     }
>>
>> A common method in common.js should be useful.
>>
>> Regards,
>>
>
>
>
> OK thanks for pointing this out. There might be a centralised method for
> this in commons.js or lists.js. Is this already taken care of in jQuery, if
> so could we use that instead?
>



-- 
Viet Nguyen

References