You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by th...@verizon.com on 2001/06/13 21:59:44 UTC

Client-side validation with Struts

How do you do client-side validation when using the Struts tags?? 
Normally, you can reference the name of the form, and the field in the
form and run a test against that by writing a function in javascript. 
However, I do not know how to reference either the form name or the
field when using the Struts tag.  

ex.  <form name=MyForm>
	<input type=text name=username>

To test agains the username field, I could access it by writing:  	if
(document.MyForm.username.value=="")
	{
		alert("Enter username");
	}

How can I do something similar to that when using the Struts tags??  For
example if my tag is:
	<html:form action="/logon">
		<html:text property="username"/>

I am in desperate need of an answer to this question, and the sooner it
can be answered the better.  If you can not do a similar type of
validation like in the first example, can you suggest a way of doing the
same type of testing?  Thank you very much.

Tom

RE: Client-side validation with Struts

Posted by Abraham Kang <ab...@infogain.com>.
I forgot how the struts tag names the forms but if you "View Source" of the
generated Struts page you should be able to see it

or

if you only had one form in the page you could use:

document.forms[0].fieldName.value ...

I think you will have to keep your javascript functions in the JSPs until
Struts 1.1 but I think you can use some of the event handlers of the
<html:xxxxxx > tags.

For example:

   <html:text name="username" onblur="checkField(this.form)"/>

--Abraham


> -----Original Message-----
> From: thomas.a.hiebler@verizon.com [mailto:thomas.a.hiebler@verizon.com]
> Sent: Wednesday, June 13, 2001 1:00 PM
> To: struts-dev@jakarta.apache.org
> Subject: Client-side validation with Struts
>
>
> How do you do client-side validation when using the Struts tags??
> Normally, you can reference the name of the form, and the field in the
> form and run a test against that by writing a function in javascript.
> However, I do not know how to reference either the form name or the
> field when using the Struts tag.
>
> ex.  <form name=MyForm>
> 	<input type=text name=username>
>
> To test agains the username field, I could access it by writing:  	if
> (document.MyForm.username.value=="")
> 	{
> 		alert("Enter username");
> 	}
>
> How can I do something similar to that when using the Struts tags??  For
> example if my tag is:
> 	<html:form action="/logon">
> 		<html:text property="username"/>
>
> I am in desperate need of an answer to this question, and the sooner it
> can be answered the better.  If you can not do a similar type of
> validation like in the first example, can you suggest a way of doing the
> same type of testing?  Thank you very much.
>
> Tom
>