W3C home > Mailing lists > Public > www-forms@w3.org > November 2000

How to write scripts referencing '/' or '.' in form input names

From: Chris Hubick <chris@hubick.com>
Date: Mon, 20 Nov 2000 17:42:57 -0500
Message-ID: <04ed01c05343$4a1c0b40$0500a8c0@chlap>
To: <www-forms@w3.org>
The Problem:

If, in a script manipulating an XForm, you try to do:

document.po_xform.purchaseOrder/shipTo/name.value = "Alice Smith";

The interpreter will try to perform division using a "shipTo" divisor and
"purchaseOrder" dividend, resulting in an "object not found" error.

If (as an aside) you try to do:

document.po_xform.purchaseOrder.shipTo.name.value = "Alice Smith";

The script interpreter will treat '.' as an object qualifier and attempt to
find the "shipTo" attribute of the "purchaseOrder" object, rather than the
"value" attribute of the "purchaseOrder.shipTo.name" object we are really

The Solution:

HTML DOM Level 2 defines an "HTMLCollection" object which has a "namedItem"
function, taking a "name" parameter as a string.  This allows you to do:

document.po_xform.elements.namedItem("purchaseOrder/shipTo/name").value =
"Alice Smith";

In this case the '/' characters will be part of a string, and be passed
directly to the namedItem function, rather than being incorrectly resolved by
the interpreter.

Currently, Internet Explorer 5.5 (didn't test other browsers or versions)
doesn't implement the standard DOM functionality.  It will, however, allow
you to do:

document.po_xform.elements["purchaseOrder/shipTo/name",0].value = "Alice

I hope this helps some people.

Chris Hubick

----- Original Message -----
From: "Chris Hubick" <chris@hubick.com>
To: <www-forms@w3.org>
Sent: Thursday, November 16, 2000 12:41 PM
Subject: DEL: Re: AW: Dots in input's names interefere with dots in XML
element names?

> Hi.
> I am implementing XForms using a combination of Java and ECMAScript
> (JavaScript/JScript).  I am using a Java applet implementation, proxying
> through LiveConnect (netscape.javascript.JSObject) to HTML forms.
> I am having problems using either '.' or '/' as qualifiers in names.
> of these characters are valid script identifiers. From what I can tell, the
> character '.' is interpreted as an object hierarchy separator, and '/' as
> division operator.  The ECMA Script 262-3 specification, section 7.6,
> specification states that even if you use unicode escapes in your scripts,
> the character codes these evaluate to must also be valid identifier
> characters.  It also states that aside from alphanumeric characters, '$'
> '_' may also be used, and that '$' is intended for use in mechanically
> generated code.  I am currently using '$', with no problems, to get my code
> working.  I have not used XPath, but as I understand it..it probably does
> place script writers in the position of needing to use '/' as an
> but rather just in strings...which is fine.
> How does the working group expect scripts to deal with these characters?
> Have others not had problems with '/' in scripts?
> I would like to vote for '$' (or '_') as a better alternative to '/'.
> Much Thanks.
Received on Monday, 20 November 2000 17:44:01 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:36:03 UTC