JQUERY FORM VALIDATION EXAMPLE

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ page import ="javax.portlet.PortletURL" %>
<%@ page import="javax.portlet.RenderResponse" %>
<%@ page import="javax.portlet.ActionRequest" %>
<portlet:defineObjects/>

<%

PortletURL addCourseURL=renderResponse.createActionURL();

addCourseURL.setParameter(ActionRequest.ACTION_NAME,"addCourse");

%>
<form action="<%=addCourseURL%>" method="post" id="register-form" >

  <div class="label1">Course Name</div>
      <input type="text" id="cname" name="cname" /> <br/>
  <div class="label2">Course Description</div>
      <input type="text" id="cdesc" name="cdesc" /> <br/>
  <div class="label3">Start Date</div>
      <input type="date" name="sdate" id="sdate"/> <br/>
<div class="label4">End Date</div>
      <input type="date" id="edate" name="edate"/> <br/>
<div style="margin-left:140px;">
      <input type="submit" name="submit" value="Submit"/>
 </div>
</form>

<script src="//code.jquery.com/jquery-1.9.1.js"></script>

<script src="//
ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js">
</script>

<script type="text/javascript">
$(function() {
       
    // Setup form validation on the #register-form element
    $("#register-form").validate({
   
        // Specify the validation rules
        rules: {
            cname: "required",
            cdesc: "required",
            sdate: "required",
            edate: "required"
        },
       
        // Specify the validation error messages
        messages: {
            cname: "Please enter course  name",
            cdesc: "Please enter course description",
            sdate: "please enter start date",
            edate: "Please enter end date"
        },
       
        submitHandler: function(form) {
            form.submit();
        }
    });

  });

</script>

Search This Blog

All the rights are reserved to this blog is belongs to me only.. Powered by Blogger.