You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by St...@gbr.xerox.com on 2004/03/03 17:53:17 UTC

RE: Form name from JSP page

Hi,

My JSP page has some javascript that need to references the html:form by
name but how elegently get the form name and input field name to achieve the
following without harcoding?

Document.forms['my_form'].elements['my_element_1']

Thanks

Stu

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


Re: Form name from JSP page

Posted by Geeta Ramani <ge...@cmpco.com>.
Hi Stu:

This is not really an answer to your question, but just a thought: Why are you
reluctant to hardcode the name of the form in? My feeling is jsps are kind of
"lightweight" elements so making them more "generalised" is not really that
important..?  I look at jsps as easily modified/modifiable and kind of
self-contained.. unless you envision putting your javascript in some "common"
place accessible to lots of jsps, maybe..?

My $0.02..:)
Regards,
Geeta

Stuart.Jameson@gbr.xerox.com wrote:

> Hi,
>
> My JSP page has some javascript that need to references the html:form by
> name but how elegently get the form name and input field name to achieve the
> following without harcoding?
>
> Document.forms['my_form'].elements['my_element_1']
>
> Thanks
>
> Stu
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


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


Re: Form name from JSP page

Posted by sean <se...@ubs.com>.



if you have 1 and only one form on the page you can do

document.all.fieldname 


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


Re: Form name from JSP page

Posted by Tim Coy <ti...@timco.net.au>.
alert(document.forms[0].getElementsByTagName("input")[0].name);

Will display the the name of the the first input field type in the first
form on the page.


var inputTags = document.forms[1].getElementsByTagName("input");
for (i = 0; i < inputTags.length; i++);
alert(inputTags[i].name);

Will display all the names of the input fields one at a time form the second
form on the page.

This is cross browser compliant.


document.all is only valid in the IE browser DOM



-- 
Tim Coy
Timco Electronics Pty Ltd
tim@timco.net.au



> Hi,
> 
> My JSP page has some javascript that need to references the html:form by
> name but how elegently get the form name and input field name to achieve the
> following without harcoding?
> 
> Document.forms['my_form'].elements['my_element_1']
> 
> Thanks
> 
> Stu
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 





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