On 18/10/2005 23:00, mike wrote:
[snip]
> <a href="javascript:void(null);"
Do not use the javascript
: pseudo-scheme in href attributes. See
<URL:http://www.jibbering.com/faq/#FAQ4_24>.
> onclick="myfunc('test2')">click</a>
>
> function myfunc(obj)
> {alert(document.obj);}
That would display the value of the obj property of the document object,
type-converted to a string.
> but I get undefined, [...]
Because there is no such property.
> alert(document.form[obj]);
That would attempt to display, assuming the call shown at the start of
your post, the test2 property of the form object in the document object.
That is, it's equivalent to:
alert(document.form.test2);
> does not work either
That's because there's no form property, but you are closer.
All form controls have a form property. As you now know, this is an
object reference to the FORM elements that contains the control.
The document object has a forms (notice the 's') property that is a
collection of all FORM elements in the document. This collection can be
indexed by id, name, or ordinal number. So, to access a form with the
name or id attribute value, test2, one would write:
document.forms.test2
If the identifier was a string value in a variable, that would be
altered to:
document.forms[myFormId]
See <URL:http://www.jibbering.com/faq/faq_notes/form_access.html> for
more information on accessing forms and form controls.
Mike
--
Michael Winter
Prefix subject with [News] before replying by e-mail.