Wednesday, December 29, 2010

AutoSubmit using JQuery

AutoSubmit using JQuery

<%@ include file="init.jsp"%>

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

<jsp:useBean class="java.lang.String" id="addNameUrl" scope="request" />

<jsp:useBean class="java.lang.String" id="make" scope="request" />

<jsp:useBean class="java.lang.String" id="model" scope="request" />



<script type="text/javascript">

       jQuery(document).ready(function(){

               jQuery('#make').change(function(){

                       jQuery('#model').show();

                        var theValue = jQuery("#make").val();

                        jQuery("#make").val( theValue ).attr('selected',true);

                       jQuery('.addForm').submit();

               });

       });

       jQuery(document).ready(function(){

               jQuery('#model').change(function(){

                        var theValue = jQuery("#model").val();;

                        jQuery("#model").val( theValue ).attr('selected',true);

                       jQuery('.addForm').submit();

               });

       });

</script>



<portlet:defineObjects />

<%

       List products = (List) CalculateLocalServiceUtil.getAllProducts();

       Deductible product = null;

%>

<form id="<portlet:namespace />addForm" action="<%=addNameUrl%>"

       method="post" class="addForm">

<%

       System.out.println("In view.jsp");

       System.out.println(products.size());

       if (make != null && make != "") {

%> <select name="make" id="make" size=1 width=10 >

       <%

               for (int i = 0; i < products.size(); i++) {

                               product = (Deductible) products.get(i);

                               if (!product.getMake().equals(make)) {

       %>



       <Option><%=product.getMake()%></option>

       <%

               } else {

       %><Option selected><%=product.getMake()%></option>

       <%

               }

                       }

       %>

</select> <%

       } else {

 %> <select name="make" id="make" size=1 width=10>

       <%

               for (int i = 0; i < products.size(); i++) {

                               product = (Deductible) products.get(i);

       %>

       <Option><%=product.getMake()%></option>

       <%

               }

       %>

</select> <%

       }

 %>



 <%

       if (make != null && make != "") {

 %> <select name="model" id="model" size=1 width=10>

       <%

               for (int i = 0; i < products.size(); i++) {

                               product = (Deductible) products.get(i);

                               if (product.getMake().equals(make)) {

                                       if(product.getModel().equals(model)){

       %>

       <Option selected><%=product.getModel()%></option>

       <%

               }else {

               %> <Option><%=product.getModel()%></option>

               <%

               }

                       }

       }%>

</select>



 <%} if (make != null && make != "" && model!=null && model!=""){ %>



       <%

               for (int i = 0; i < products.size(); i++) {

                       product = (Deductible) products.get(i);

                       if (product.getModel().equals(model)&& product.getMake().equals(make)){

                       %>

                       <label for="text1" id="label1"><%=product.getDeductible()%></label>

                       <%

                       make="";

                       model="";

                       }

                       }

 }



 %>







</form>

No comments:

Post a Comment