struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Caroline Jen <>
Subject Re: two form one jsp
Date Tue, 01 Aug 2006 14:15:53 GMT
1. Each element in a document must have a unique id.

This element is then accessed in script using

e.g. <p id="myP">...</p> -->

If more than one element has the same id and you try
to use that id 
with document.getElementById(), the method doesn't
know which element 
you're talking about, and an error results.

2. <form name="findUsers"> <-->
document.forms["findUsers"] or 

<form id="findUsers"> <-->

3. Only form elements have a value attribute.

Only form elements can pass a value with a form when
the form is submitted.

<a> is not a form element.


<form name="myForm">
<input name="myField" type="text" value="something">
<input name="myOtherField" type="text"
<input name="mySubmit" type="submit" value="Click to

Assuming that this is the first or only form in the

The form can be referenced as:


All but the first two of these require that the form
have a name 
attribute whose value is "myForm". An id attribute
will not work for this.

Now, let's assume that we set a variable theForm equal
to one of these 
references to the form whose name (not id) is
"myForm". The first input 
in this form can then be referenced as any of the


All but the first two of these require the the input
have the name (not 
id) "myField". Similarly, the second input can be
accessed as any of the 


All but the first two of these require the the input
have the name (not 
id) "myOtherField".

You can give a form or form element element an id
attribute and then 
access it using document.getElementById() as well as 
getElementsByTagName(). However, you cannot use the id
attribute value 
for forms and element array references.

Suppose you have this:

<form id="myForm">
<!-- ...form elements... -->

Then none of these references will work for the form:


In each case, you'll get an error saying that the
object reference is 
null, undefined, or isn't an object. The exact wording
of the message 
depends on which browser you're using, but they all
mean the same thing: 
"I've no idea what you're talking about".

This appears to be the root of your problem.

The short version: Give name attributes to all your
form and form 
element tags. You should do this in any case, since
serverside scripts 
don't read id's. You needn't bother with an id
attribute for a form or 
form element unless you want to (a) access it in a
script by means of 
document.getElementById() or (b) you want to style it
using a CSS id 
selector (e.g. form#myForm or #myForm).

--- Li <> wrote:

> Hi,
> Would it be possible if you can combine two form to
> one but have two
> object behind to accept the dat from form you
> submit?
> On 8/1/06, Krishna, Hari <>
> wrote:
> > pass the formbean name at run time change the
> logic It works for me:)
> >
> > -----Original Message-----
> > From: Parvat Singh Ranawat
> []
> > Sent: Monday, July 31, 2006 11:32 PM
> > To:
> > Subject: two form one jsp
> >
> >
> > Hi all,
> >
> > I'm attempting to create a JSP that is made up of
> two forms.  Each
> > form needs a same  form bean and is processed by a
> same
> > action.  The catch is that the one form comes from
> Header (This will be
> > there for all the pages as part of left panel )
> >
> >  and second is coming from my jsp  and  problem
> occures while calling JAVA
> >
> > ie
> > 1) if I use document. form[0]  then this always
> points to the first form
> > (which is there in Header)
> > 2) if I use document.formName
> >  then there is ambiguity which form to call.
> >
> > so how to work in this situation
> >
> >
> > Thanks
> >
> > Shakti
> > Notice:  All email and instant messages (including
> attachments) sent to
> > or from Franklin Templeton Investments (FTI)
> personnel may be retained,
> > monitored and/or reviewed by FTI and its agents,
> or authorized
> > law enforcement personnel, without further notice
> or consent.
> >
> >
> > To unsubscribe, e-mail:
> > For additional commands, e-mail:
> >
> >
> -- 
> When we invent time, we invent death.
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message