It's generally something to avoid because you may at some point change
the order of your forms and then find that your code no longer works.
Think of what happens if you put a form before this one later... now the
form you want is actually form[1], and things break until you find and
change all the code.
With modern browsers your best bet is to set an ID on the form and use
document.getElementById(). Note that you can also access the form using
document.forms["name"] where name is of course the name attribute of the
form.
Note also that styleId is the attribute of <html:form> that you want,
that renders an ID attribute (unfortunate naming choice since it
encourages the usage of the ID attribute to assign CSS classes, which is
another bad practice IMO, but whatever, it works!).
Frank
Tamas Szabo wrote:
If there is no name associated with your declared HTML form then use
document.forms[0] (basically the first form defined for the HTML document)
Personally I caution against using this convention as the caller does not
properly identify the form (by name)
Hi Martin!
Why do you caution against using forms[0]?
I'm not arguing against this, I'm a total newbie in javascript.
I just ask because I had to reference the form and I used
forms[0] despite of the fact that I'm using html:form and I have
the name of the form.
But the html:form is generated based on the action attribute
so I thougth that if someone changes the action mapping in struts
config the javascript won't break with forms[0].
Isn't the forms[0] reliable?
Note that I have only one form in my jsp page.
Thanks,
Tamas
Anyone else ?
M-
----- Original Message -----
From: "Jason King" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Tuesday, September 13, 2005 11:05 AM
Subject: Re: How to replace normal html-from through html:form in Struts?
Example
gollinger wrote:
<form name="next" action="/jsp/awp/awpoutput.jsp" target="display" />
<script language="javascript">
document.next.submit();
</script>
The problem I have is that the form tag in Struts has no name!
Why?
So how can I execute the java-script? Which name should I use instead?
Regards Antonio
document.form[0] or form[1] will work.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]