1

I have 2 jsp files. display.jsp and content.jsp. content.jsp is included in display.jsp i have a form in content.jsp for which i want to perform validation in display.js

Display.jsp
display.js included here
<%@ include file="content.jsp" %>


Content.jsp
<form id="frm" name="frm">
<table width="435px" height ="235px" id ="remtable" align="left" cellpadding="0" cellspacing="0"  border="0" class="remarkstable">
<tr>
<td>
<input name="field1" type="text" id="field1" size="40" maxlength="60">
</td>
</tr>
</table>
</form>

display.js
$("#frm").validate({

    focusCleanup : false,
    onkeyup : false,
    onfocusout : false,
    focusInvalid : false,
    onsubmit : true,

    rules:{
        field1:{
         required: function() {
             if ($('#field1').val() == "") {
                    alert("true");
                    return true;
                } else {
                    alert("false");
                    return false;
                }
           }
        }
    },
    messages:{
        uploadfile:{
            required : "Enter Subject"
        }
    }
});

The validate method is outside document ready as it is only for display.jsp. I call the validate method from onclick of content.jsp using .valid(). Validation dosen't happen. Any help ?

sahana
  • 601
  • 5
  • 12
  • 33
  • Put the function in a document ready handler - you're allowed to have multiple document ready handlers on a page. Or include `display.js` at the end of the body (or at least after the form it refers to). – nnnnnn May 29 '13 at 11:02

1 Answers1

0

simply write another ready in the jsp where your form exists.

You can use any number of Document.ready() function.

They executes one by one.

jQuery - multiple $(document).ready ...?

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • will it work for the included jsp? there are two jsps one included in the other. For second jsp, validation must be performed from first jsp's js. – sahana May 29 '13 at 11:08
  • sahana, the JS is executed by the browser, which doesn't know that there were two JSPs. The browser only sees the single response generated by the two JSPs. – nnnnnn May 29 '13 at 11:10
  • i m always getting true for it !! – sahana May 29 '13 at 11:46