Are you going directly to the JSP page or are you
going through an action?  I suspect you are going
through an action and you have 'validate="true"'. 
This would cause the page to be validated before it
was actually submitted.  So you could either go
directly to a JSP or have 'validate="false"' and have
a hidden field (like action) so you can tell whether
or not to validate in the action itself.

David

--- Greg Wilson <[EMAIL PROTECTED]> wrote:
> I've written a small login/password app using Struts
> and Validator.
> The client & server side validation is working well,
> except for one
> thing: the "required field" error messages (i.e.
> User Name is required)
> are displayed when the page is first displayed.
> 
> I've attached the HTML that is generated when the
> page is initially
> displayed.
> 
> Thanks,
> Greg Wilson
> 
> __________________________________________________
> Terrorist Attacks on U.S. - How can you help?
> Donate cash, emergency relief information
>
http://dailynews.yahoo.com/fc/US/Emergency_Information/
<HR>
<html lang="en">
<head>
    <title>
        VPNSC Login
    </title>
    <SCRIPT LANGUAGE="Javascript1.1"> 
<!-- Begin 

         var bCancel = false; 

         function validateLoginForm(form) {                  
                                                
              if (bCancel) 
                return true; 
              else 
                return validateRequired(form); 
         } 

         function required () { 
            this.aa = new Array("userName", "User Name is
required.", new Function ("varName", " return
this[varName];"));
            this.ab = new Array("password", "Password is
required.", new Function ("varName", " return
this[varName];"));
         } 



function validateRequired(form) {

                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
                oRequired = new required();

                for (x in oRequired) {
                    if ((form[oRequired[x][0]].type ==
'text' ||
form[oRequired[x][0]].type == 'textarea' ||
form[oRequired[x][0]].type == 'select' ||
form[oRequired[x][0]].type == 'radio' ||
form[oRequired[x][0]].type == 'password') &&
form[oRequired[x][0]].value == '') {
                       if (i == 0)
                          focusField =
form[oRequired[x][0]];

                       fields[i++] = oRequired[x][1];
                       bValid = false;
                    }
                }

                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('\n'));
                }
                return bValid;
            }

//  End -->
</SCRIPT>


    <script type="text/javascript"
language="JavaScript">
    </script>
</head>
<body>
    <tr>
        <td colspan="3" align="center">
            <ul>
                <li><span style="color:red;">Password
is required.</span></li>
            
                <li><span style="color:red;">User Name
is required.</span></li>
            </ul><hr>
        </td>
    </tr>

    <form name="loginForm" method="POST"
action="/vpnsc/verify.do" onsubmit="return
validateLoginForm(this);">
    <table border="0" width="100%">

    <tr>
        <th align="right">
            User name:
        </th>
        <td align="left">
            <input type="text" name="userName"
maxlength="16" size="16" value="">
        </td>
    </tr>

    <tr>
        <th align="right">
            Password:
        </th>
        <td align="left">
            <input type="password" name="password"
maxlength="16" size="16" value="">
        </td>
    </tr>

    <tr>
        <td align="right">
            <input type="submit" name="submit"
value="Log In">
        </td>
        <td align="left">
            <input type="reset" name="reset"
value="Clear">
        </td>
    </tr>
    </table>
</form>
<script language="JavaScript" type="text/javascript">
  <!--
   
document.forms["loginForm"].elements["userName"].focus()
  // -->
</script>

</body>
</html>


__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

Reply via email to