[webkit-dev] What data structure is used to store multiple input controls sharing the same name?

Marco Wise marco.wise at stanford.edu
Mon Mar 27 12:13:39 PST 2006


Hi Darin,

Thanks for your reply, I filed a bug report (http:// 
bugzilla.opendarwin.org/show_bug.cgi?id=7967) and included a test case.
I'm trying to track down an issue with the CPAN module  
CGI::FormBuilder. It creates client side javascript validation code  
that unfortunately does not work with Safari/Konqueror/OmniWeb, etc.

Thanks!

- marco

On Mar 27, 2006, at 12:02 PM, Darin Adler wrote:

> On Mar 20, 2006, at 10:13 AM, Marco Wise wrote:
>
>> What kind of data structure/object is used internally by Safari /  
>> Konqueror to store multiple inputs with the same name? Is it a  
>> NodeList as in IE/Firefox, or something different? Can properties  
>> be assigned to this object using Javascript?
>>
>> Using the code below it looks like Firefox, IE and Safari create  
>> an HTMLInputElement the first time a control named _submit is  
>> encountered.
>> The second time a control named _submit is encountered, it seems  
>> that a data structure is created to hold the HTMLInputElements and  
>> these can then be accessed using array notation.
>>
>> Firefox/IE report that this new structure is a Nodelist, but  
>> Safari only reports that it's an "object". When I try using  
>> toString() to get more information but then Safari reports an  
>> error that it's not an object.
>>
>> Finally,
>> In Firefox/IE you can assign new properties to this new Nodelist  
>> as in _submit.foo = "bar" and you can retrieve their value.
>> In Safari (I'm using 2.0.3) doing so will fail silently and  
>> retrieving them will return "undefined".
>>
>> The code I'm using to try to sort this out:
>>
>> <html>
>> <form name="test_form" onsubmit="test(this);">	
>> 	<input type="submit" name="_submit" value="One">
>> 	<script>
>> 	  alert("_submit is a " + document.forms[0]._submit);
>> 	  alert("_submit's value is " + document.forms[0]._submit.value);
>> 	</script>
>> 	<input type="submit" name="_submit" value="Two">
>> 	<script>
>> 	  alert("_submit is now a " + document.forms[0]._submit);
>> 	  alert("_submit's value is now " + document.forms 
>> [0]._submit.value);
>> 	  alert("Assigning a value to _submit...");
>> 	  document.forms[0]._submit.value = "New Value";
>> 	  alert("_submit's value is now " + document.forms 
>> [0]._submit.value);
>> 	  alert("The original _submit's value can still be reached as an  
>> item: " + document.forms[0]._submit[0].value);
>> 	</script>
>> </form>
>> </html>
>>
>> I've looked at the webkit source code but I'm not an expert at C++  
>> so I am not quite sure where to find this information. I've also  
>> tried calling functions that should work on Nodelists and arrays  
>> on this object and they fail. The only property that seems to work  
>> is "length".
>>
>> To recap, my question is: how does Safari store multiple input  
>> controls that share the same name? Can this object have its own  
>> properties (besides "length")?
>>
>> Thanks in advance for any help you can provide,
>
> Here are some implementation details. I don't know if they will  
> help you solve whatever problem you're working on.
>
> document.forms is an HTMLCollection.
>
> The function used to get an item by name in an HTML collection  
> exists only in the JavaScript binding in Safari. It's  
> JSHTMLCollection::getNamedItems, in kjs_html.cpp.
>
> The class used when there is more than one item with the same name  
> is DOMNamedNodesCollection, defined in kjs_dom.h/cpp. Looking at  
> DOMNamedNodesCollection::getOwnPropertySlot, it looks like it  
> supports length, indexing by number, and indexing by ID.
>
> Would you consider filing a bug report about the problem you're  
> encountering?
>
>     -- Darin
>




More information about the webkit-dev mailing list