|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
select.add(v)
How does select.add() work ?
Error: uncaught exception: [Exception... "Not enough arguments [nsIDOMHTMLSelectElement.add]" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://localhost/gert/db4/js/html.js :: op :: line 23" data: no] select.add(v) Error: uncaught exception: [Exception... "Could not convert JavaScript argument - 0 was passed, expected object. Did you mean null? arg 0 [nsIDOMHTMLSelectElement.add]" nsresult: "0x80570035 (NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL)" location: "JS frame :: http://localhost/gert/db4/js/html.js :: op :: line 23" data: no] select.add(0,v) |
|
#2
|
|||
|
|||
|
function op(n,v)
{ i = document.getElementsByName(n)[0].options.length option = document.createElement('option') option.value = v option.text = v document.getElementsByName(n)[0].add(option,i) } also doesnt work
|
|
#3
|
|||
|
|||
|
function op(n,v)
{ i = document.getElementsByName(n)[0].options.length option = document.createElement('option') option.value = v option.text = v document.getElementsByName(n)[0].options.add(option,i) } But this does
|
|
#4
|
||||
|
||||
|
A few notes.
1. Should really be using: new Option("text","value") not createElement and spam 3 extra lines. 2. getElementsByName is glitchy in IE. 3. If you want to append a new OPTION to the end of a SELECT dropdown menu, instead of counting all the OPTIONS there are and sending that number as a 2nd argument to the "add" method, just send it null instead. Code:
function op(n,v)
{
document.getElementsByName(n)[0].options.add(new Option(v,v),null);
}
Besides, it's better to make sure the element actually exists before calling the function and instead sending it a reference. Code:
function op(e,v)
{
e.options.add(new Option(v,v),null);
}
![]() Then again, I tend to avoid the "add" and "remove" methods myself. Code:
e.options[e.options.length]=new Option("text","value");
__________________
Ultimater XMLHttpRequest: Specification | xmlhttp object | open and onreadystatechange order | String.prototype.toXMLDocument | Sarissa | Prototype | Dojo Broadening one's horizons: 24ways.org Note I have a bad habit of editing my posts hours at a time and hours later. Last edited by Ultimater; 09-03-2006 at 07:35 AM. |
|
#5
|
|||
|
|||
|
Makes me wonder how many other spam lines i have in my code lol
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|