0 Replies Latest reply on May 23, 2009 4:55 AM by Alyssa Kay

    JSP's servlet and javascript not working together

    Alyssa Kay Newbie

      Hi everyone,

      I'm having trouble trying to get javascript running on a form in addtion to a servlet. Its a login form, I would like to check if the fields have been filled in, prompting the user if they have not. Once both fields are completed the action will call a controller servlet that will the rest of the work. Currently when i define in the jsp

      <form name="login_form" method="post" onsubmit="return validate_form()" action="Controller">
       <input type="hidden" name="action" value="login"/>
      
       <table cellSpacing="3" cellPadding="0" border="0" style="border: medium none" id="loginTable">
       <tr>
       <td class="smallheaderfont">
       <label for="login_username" style="cursor: default">User Name</label>
       </td>
       <td class="inputfieldfont">
       <input class="bginput" id="login_username" style="FONT-SIZE: 11px" onfocus="" accessKey="u" tabIndex="1" size="10" name="username_output">
       </td>
       </tr>
       <tr>
       <td class="smallheaderfont">
       <label for="login_password" style="cursor: default">Password</label>
       </td>
       <td class="inputfieldfont">
       <input class="bginput" id="login_password" style="FONT-SIZE: 11px" onfocus="" accessKey="u" tabIndex="2" size="10" name="password_output">
       </td>
       </tr>
       <tr>
       <td></td>
       <td class="inputfieldfont">
       <input class="button" accessKey="s" tabIndex="104" type="submit" value="Log in" align= "right">
       </td>
       </tr>
       </table>
       </form>
      


      The javascript function is basic:

      <script type="text/javascript">
      
       function validate_form ( )
       {
       valid = true;
      
       if ( document.login_form.username_output.value == "" )
       {
       alert ( "Please fill in the 'User Name' field." );
       /*document.register_form.firstname_output.value.focus();*/
       valid = false;
       }
       if ( document.login_form.password_output.value == "" )
       {
       alert ( "Please fill in the 'Password' field." );
       /*document.register_form.lastname_output.value.focus();*/
       valid = false;
       }
      
       if(valid){
       return true;
       }else{
       return false;
       }
       }
       </script>
      



      I think its more of an issue of how to define the servlet action after the javascript in the form definition. I have asked this question in javascript forums.

      p.s. sorry about the formatting.

      If you could help i would appreciate it.

      Thanks, Alyssa.