Bug inserting in the 0 position of a HTMLSelect element.

13 views
Skip to first unread message

Andres Navidad

unread,
Feb 23, 2012, 7:37:47 AM2/23/12
to jaxcen...@googlegroups.com
Hi,

The Javascript code inlcudes zero as an invalid value in the select and set the value to insert into the DOM of the select to null.

The documentation states:

Insert an OPTION in the SELECT at the specified index.  If index is -1, the OPTION is inserted at the end.  The attributes and value arrays must have the same length.  These attributes are added to the option.

In W3 reference:
->selectDOM.add (element, before)
------>Parameters
------>element of type HTMLElement
---------------->The element to add.
------>before of type HTMLElement
----------------->The element to insert before, or null for the tail of the list.

The code is the next:

function JaxcentAddOption( sel, opt, index )
{
    if ( index <= 0 || index >= sel.options.length ) {
        try {
            sel.add( opt, null );
            return;
        } catch (e) {
        }
        try {
            sel.add( opt, sel.options.length );
            return;
        } catch (e) {}
        sel.add( opt );
        return;
    }
    try {
        sel.add( opt, index );
        return;
    } catch (e) {}
    sel.add( opt, sel.options[index] );
}

With
this change has fixed the bug.







Mukesh Prasad

unread,
Feb 23, 2012, 8:11:54 AM2/23/12
to jaxcen...@googlegroups.com
Nice catch!  / Mukesh
--
You received this message because you are subscribed to the Google Groups "Jaxcent" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jaxcentgroup/-/_DZnyB6p-k8J.
To post to this group, send email to jaxcen...@googlegroups.com.
To unsubscribe from this group, send email to jaxcentgroup...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jaxcentgroup?hl=en.
Reply all
Reply to author
Forward
0 new messages