struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Jouravlev" <jmi...@gmail.com>
Subject Re: two form one jsp
Date Wed, 02 Aug 2006 17:08:53 GMT
http://www.w3.org/TR/REC-DOM-Level-1/level-one-html.html#ID-36113835

On 8/1/06, Monkeyden <monkeyden@gmail.com> wrote:
> Caroline (or Jen?)
> All I can say is "Wow!"  document.getElementById() only works in IE, not
> FF.  Your response is an arduous elaboration of my document.forms[0] and
> document.forms[1], which is the correct solution.
>
> On 8/1/06, Caroline Jen <jiapei_jen@yahoo.com> wrote:
> >
> > 1. Each element in a document must have a unique id.
> >
> > This element is then accessed in script using
> > document.getElementById().
> >
> > e.g. <p id="myP">...</p> -->
> > document.getElementById("myP")
> >
> > 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
> > document.findUsers
> >
> > <form id="findUsers"> <-->
> > document.getElementById("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.
> >
> > Example:
> >
> > <form name="myForm">
> > <input name="myField" type="text" value="something">
> > <input name="myOtherField" type="text"
> > value="something-else">
> > <input name="mySubmit" type="submit" value="Click to
> > Submit">
> > </form>
> >
> > Assuming that this is the first or only form in the
> > page:
> >
> > The form can be referenced as:
> >
> > document.forms[0]
> > document.getElementsByTagName("form")[0]
> > document.forms["myForm"]
> > document.forms.myForm
> > document.myForm
> > document.getElementsByName("myForm")[0]
> >
> > 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
> > following:
> >
> > theForm.elements[0]
> > theForm.getElementsByTagName("input")[0]
> > theForm.elements["myField"]
> > theForm.elements.myField
> > theForm.myField
> > theForm.getElementsByName("myField")[0]
> >
> > 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
> > following:
> >
> > theForm.elements[1]
> > theForm.getElementsByTagName("input")[1]
> > theForm.elements["myOtherField"]
> > theForm.elements.myOtherField
> > theForm.myOtherField
> > theForm.getElementsByName("myOtherField")[0]
> >
> > 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... -->
> > </form>
> >
> > Then none of these references will work for the form:
> >
> > document.forms["myForm"]
> > document.forms.myForm
> > document.myForm
> >
> > 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 <ampyx.li@gmail.com> 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 <HKrishn1@templeton.com>
> > > wrote:
> > > > pass the formbean name at run time change the
> > > logic It works for me:)
> > > >
> > > > -----Original Message-----
> > > > From: Parvat Singh Ranawat
> > > [mailto:mailtoparvat@gmail.com]
> > > > Sent: Monday, July 31, 2006 11:32 PM
> > > > To: user@struts.apache.org
> > > > 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
> > > > SCRIPT
> > > >
> > > > 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

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message