eus Posted January 16, 2009 Share Posted January 16, 2009 Hi Ho!Browsing w3schools' DHTML, HTML DOM, JavaScript, and XHTML, I know that `createElement()' should be used to create a new HTML element, and it is only possible to do so with XHTML documents. So, I was surprised when I found out that I can do `new Option([text[, value[, defaultSelected[, selected]]]])' to create a new HTML Option element to be added to an HTML Select element. I found someone in the same situation: http://www.coderanch.com/t/120551/HTML-Jav...ion-Constructor.Does anyone know why w3schools doesn't mention `new Option([text[, ...]]]])' construct at all? Is it because `new Option()' construct not standard? Even so, w3schools should say something about this construct so as to be complete.In addition to that, does anybody know who specified the order of the arguments to the constructor of `new Option([text[, value[, defaultSelected[, selected]]]])' construct? Is it Sun Microsystem through its `Client-Side JavaScript Reference' ( http://docs.sun.com/source/816-6408-10/contents.htm )?Thank you.Best regards,Eus Link to comment Share on other sites More sharing options...
Synook Posted January 16, 2009 Share Posted January 16, 2009 http://www.w3schools.com/htmldom/dom_obj_option.asp... Link to comment Share on other sites More sharing options...
inktherapy Posted January 16, 2009 Share Posted January 16, 2009 I also thought I already exhausted reading all w3school javascript tutorial but I was wrong, It always surprises me suddenly a new topic exist. Link to comment Share on other sites More sharing options...
eus Posted January 16, 2009 Author Share Posted January 16, 2009 Hi Ho! http://www.w3schools.com/htmldom/dom_obj_option.asp...Yes, I have perused that page previously when I was looking for a reference on w3schools.Unfortunately, the given page only says:For each instance of an <option> tag in an HTML form, an Option object is created.But, the page does not say anything about the possibility of creating an Option object in JavaScript by doing `new Option([text[, value[, defaultSelected[, selected]]]])' , let alone describing the order of the arguments (c.f., http://docs.sun.com/source/816-6408-10/option.htm)So, the question remains: why does w3schools not mention `new Option([text[, ...]]]])' construct at all?Thanks.Best regards,Eus Link to comment Share on other sites More sharing options...
boen_robot Posted January 16, 2009 Share Posted January 16, 2009 Now that you mention it, I think there isn't a single object that has its constructor described. Then again, you can always use document.createElement(), and set the attributes yourself. Link to comment Share on other sites More sharing options...
eus Posted January 19, 2009 Author Share Posted January 19, 2009 Hi Ho!Okay, it seems that no one knows why w3schools doesn't mention `new Option([text[, ...]]]])' construct at all.So, let me conclude that the construct `new Option([text[, value[, defaultSelected[, selected]]]])' is not the standard way to construct an HTML Option element in favor to `createElement()', and that the standard that standardizes the arguments of the construct can be found in the Sun website. It is titled `Client-Side JavaScript Reference'.Best regards,Eus Link to comment Share on other sites More sharing options...
Synook Posted January 19, 2009 Share Posted January 19, 2009 The "Client-Side JavaScript Reference" by Sun is not a standard, it has no specification, and is not officially binding (it is a reference). If you would look, it was also written in 1998. The official W3C DOM standard, of which createElement() is part of, specifies ObjectHTMLOptionElement as an interface, though its IDL documentation, and as interfaces have no constructors there is technically no standard governing the constructor for Object and other HTMLElements, and one is not possible. Therefore I would conclude that the Option object as described in the Sun documentation is a throwback to allow the addition of new elements from before the standardisation of the DOM (being written in 1998, this is not suprising) and should not be used.P.S. The development of JavaScript is currently and has been for some time undertaken by the Ecma, and Sun's involvement in the evolution of the language has been rather sparse and was mostly limited to the time in which Netscape Communications was the prime proponent of JavaScript. The Document Object Model is developed by the W3C. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.