Results 1 to 7 of 7
  1. #1
    ashish1987 is offline Member
    Join Date
    Apr 2012
    Location
    Delhi
    Posts
    10
    Rep Power
    0

    Default Jquery validation in struts with ajax

    Hello friends,
    I am using jquery validation in drop down list in struts2. Drop Down list receives data from Ajax . I am using Ajax by jquery plugin. And give the headerKey="-1" in list attribute of drop down list. Now problem is that validation is not working on the drop down list. Please give me a solution if you have............thank you..

  2. #2
    ashish1987 is offline Member
    Join Date
    Apr 2012
    Location
    Delhi
    Posts
    10
    Rep Power
    0

    Default Re: Jquery validation in struts with ajax

    hello friends,
    this is the code in which jquery validation is not working in drop down list in struts2. Please give me a suitable solution.


    <script type="text/javascript">
    $().ready(function() {

    // validate Registration form on keyup and submit
    /* $().validator.addMethod('correctCountFilled', function(value, element) {
    alert(jQuery('#login_check').text());
    if(jQuery('#login_check').text()=="tis is test page"){
    alert(jQuery('#login_check').text());
    return true;
    }
    else
    {
    alert("plese check user name first");
    return false;
    }

    });*/


    /* $("#psa_registration").submit(function(psa_registr ation)
    {
    var s = $('#login_check').text();
    alert("1");
    var g = $('#gender');
    var t = $('#idcountry');
    alert(t);
    alert(g);
    alert(s);
    if(s == "tis is test page")
    return true;
    else
    return false;
    //this runs when the form validated successfully
    psa_registration.submit(); //submit it the form

    });

    */

    $.validator.addMethod("loginRegex", function(value, element) {
    return this.optional(element) || /^[a-zA-Z]+$/i.test(value);
    }, "Username must contain only letters");


    $.validator.addMethod("addRegex", function(value, element) {
    return this.optional(element) || /^[a-z0-9\-]+$/i.test(value);
    }, "Address must contain only letters, numbers, or dashes.");

    $("#psa_registration").validate({

    rules:
    {
    login_name:
    {
    required:true,
    loginRegex:true,
    minlength:5,
    maxlength:20,
    }
    ,
    agency_name:
    {
    required:true,
    loginRegex:true,
    maxlength:50,
    },
    first_name:
    {
    required:true,
    loginRegex:true,
    maxlength:50,
    },
    last_name:
    {
    required:true,
    loginRegex:true,
    maxlength:50,
    },
    gender:"required",
    email:
    {
    required:true,
    email:true
    },
    address:
    {
    required:true,
    addRegex:true,
    maxlength:250,
    },
    ----------------------------------------------
    idcountry:
    {
    required:true
    },
    ------------------------------------------------

    /* {required:function()
    {
    var g = $('#idcountry');
    alert(g);
    alert(g.val());
    return g.val() >= 0;
    }},
    */
    state:"required",
    city:"required",
    pincode:
    {
    required:true,
    minlength:6,
    maxlength:6,
    digits:true,
    },
    phone:
    {
    required:true,
    minlength:10,
    maxlength:15,
    digits:true,
    },
    mobile:
    {
    required:true,
    minlength:10,
    maxlength:15,
    digits:true,
    },
    pan_number:"required",
    user_type:"required",


    },

    messages:
    {
    login_name:
    {
    required:"Enter Name",
    },
    agency_name:
    {
    required:"Enter Agency Name",
    },
    first_name:
    {
    required:"Enter First Name",
    },
    last_name:
    {
    required:"Enter Last Name",
    },
    gender:"Enter Your Gender",
    email:
    {
    required:"Enter Email",
    email:"Enter Valid Email"
    },
    address:
    {
    required:"Enter Address",
    addRegex:"Enter Valid Address"
    },
    ------------------------------------------------------
    idcountry:
    {
    required:"Enter Country",
    },
    state:"Enter State Name",
    city:"Enter City Name",
    --------------------------------------------------------
    pincode:
    {
    required:"Enter Pincode",
    },
    phone:
    {
    required:"Enter Phone Number",
    },
    mobile:
    {
    required:"Enter Mobile Number",
    },
    pan_number:"Enter Pan Number",
    user_type:"Enter User Class",

    }

    });
    });
    </script>

    </head>
    <body>
    <div class="main_register">
    <div class="header_register">
    <span class="header_register_text">Register New PSA</span>
    <span class="login_here"><a href="welcome.action">Login Here</a></span>
    </div>
    <div class="form_register">
    <s:form method="post" action="register_psa" id="psa_registration" theme="css_xhtml" >
    <s:hidden name="id"/>
    <table>
    <tr>
    <td><s:label>Login Name</s:label> </td>
    <td><s:textfield name="login_name" id="login_name"/></td>
    <td><s:url id="simpleecho" action="testAction"/>
    <sj:submit id="formSubmit2" targets="login_check" href="%{simpleecho}" button="true" onBeforeTopics="" />
    <s:div id="login_check" name="login_check" ></s:div></td>
    </tr>
    <tr>
    <td><s:label>Agency Name</s:label></td>
    <td colspan=2><s:textfield name="agency_name" id="agency_name"/></td>
    </tr>
    <tr>
    <td><s:label>First Name</s:label></td>
    <td colspan=2><s:textfield name="first_name" id="first_name"/></td>
    </tr>
    <tr>
    <td><s:label>Last Name</s:label></td>
    <td colspan=2><s:textfield name="last_name" id="last_name"/></td>
    </tr>
    <tr>
    <td><s:label>Gender</s:label></td>
    <td colspan=2><s:select list="{'Male','Female'}" name="gender" id="gender" headerKey="" headerValue="Select Gender"/></td>
    </tr>
    <tr>
    <td><s:label>Email</s:label></td>
    <td colspan="2"><s:textfield name="email" id="email"/></td>
    </tr>
    <tr>
    <td><s:label>Address</s:label></td>
    <td colspan="2"><s:textarea name="address" id="address" cols="20" rows="6"/></td>
    </tr>
    <tr>
    <td>
    <s:label>Country</s:label></td>
    <td colspan="2">

    <s:url id="countrylist" action="lstcountryaction"/>
    ----------------------------------------------------------------------
    <sj:select
    list="lstcountry"
    listKey="idcountry"
    listValue="countryname"
    href="%{countrylist}"
    headerKey="-1"
    headerValue="-select country-"
    id="idcountry"
    name="idcountry"
    onChangeTopics="reloadstatelist,reloadcitylist"
    onCompleteTopics="reloadstatelist,reloadcitylist"
    onchange="javascript:show_textbox('idcountry','O_c ountry');"
    />
    -----------------------------------------------------------------------------------
    </td>
    </tr>
    <tr id="O_country" style="display:none">
    <td><s:label>Other country</s:label> </td>
    <td colspan="2"><s:textfield name="other_country" id="other_country" /></td>
    </tr>
    <tr>
    <td><s:label>State</s:label></td>
    <td colspan="2">
    <s:url id="statelist" action="lststateaction"/>
    <sj:select list="lststate" listKey="idstate" listValue="statename" href="%{statelist}" formIds="psa_registration" headerKey="-1" headerValue="-select state-"
    id="idstate" name="idstate" reloadTopics="reloadstatelist" deferredLoading="true" onChangeTopics="reloadcitylist" onCompleteTopics="reloadcitylist"
    onchange="javascript:show_textbox('idstate','O_sta te');"/>
    </td>
    </tr>
    <tr id="O_state" style="display:none">
    <td><s:label>Other state</s:label> </td>
    <td colspan="2"><s:textfield name="other_state" id="other_state" /></td>
    </tr>
    <tr>
    <td><s:label>City</s:label> </td>
    <td colspan="2">
    <s:url id="citylist" action="lstcityaction"/>
    <sj:select list="lstcity" listKey="idcity" listValue="cityname" href="%{citylist}" formIds="psa_registration" headerKey="-1" headerValue="-select city-"
    id="idcity" name="idcity" reloadTopics="reloadcitylist" deferredLoading="true" onchange="javascript:show_textbox('idcity','O_city ');" />
    </td>
    </tr>
    <tr id="O_city" style="display:none">
    <td><s:label>Other city</s:label> </td>
    <td colspan="2"><s:textfield name="other_city" id="other_city" /></td>
    </tr>
    <tr>
    <td><s:label>Pin Code</s:label> </td>
    <td colspan="2"><s:textfield name="pincode" id="pincode"/></td>
    </tr>
    <tr>
    <td><s:label>Phone</s:label> </td>
    <td colspan="2"><s:textfield name="phone" id="phone"/></td>
    </tr>
    <tr>
    <td><s:label>Mobile</s:label> </td>
    <td colspan="2"><s:textfield name="mobile" id="mobile"/></td>
    </tr>
    <tr>
    <td><s:label>Pan Number</s:label> </td>
    <td colspan="2"><s:textfield name="pan_number" id="pan_number"/></td>
    </tr>
    <%
    String usertype=(String)session.getAttribute(constants.Co nstants.SESSION_USER_TYPE);
    if(usertype!=null)
    if(!usertype.equals(constants.Constants.USER_ADMIN ))
    {
    %>
    <tr>
    <td><s:label>User Class</s:label> </td>
    <td colspan="2"><s:select name="user_class" id="user_class" list="{'Platinum','Gold','Silver'}" headerKey="" headerValue="Select User Class" /></td>
    </tr>

    <tr>
    <td><s:label>Distributor Id</s:label> </td>
    <td colspan="2"><s:textfield name="distributor_id"/></td>
    </tr>
    <%} %>
    <%
    if(usertype!=null)
    if(usertype.equals(constants.Constants.USER_ADMIN) )
    {
    %>
    <tr>
    <td><s:label>User Type</s:label> </td>
    <td colspan="2"><s:select name="user_class" onchange="javascript:showme();" id="user_class" list="#{'3':'Distributor','1':'Adminstrator','2':' User'}" headerKey="0" headerValue="Select User Type" /></td>
    </tr>
    <tr id="showme" style="display:none">
    <td><s:label>User Class</s:label> </td>
    <td colspan="2"><s:select name="user_type" id="user_class" list="{'Platinum','Gold','Silver'}" headerKey="" headerValue="Select User Class" /></td>
    </tr>

    <tr>
    <td><s:label>Administrator Id</s:label> </td>
    <td colspan="2"><s:textfield name="distributor_id"/></td>
    </tr>
    <%} %>
    <tr>
    <td colspan="3"><s:submit value="Submit" /></td>
    </tr>
    </table>
    </s:form>
    </div>
    <div style="clear:both;"></div>
    </div>

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Jquery validation in struts with ajax

    1. You need to use [code] tags [/code] when posting code.
    2. Isn't this a JQuery question?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Jquery validation in struts with ajax

    No, you haven't used [code] tags [/code].
    And what on earth was the point of PMing me rather than posting here?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Jquery validation in struts with ajax

    Java Code:
    <script type="text/javascript">
    $().ready(function() {
    	
    	// validate Registration form on keyup and submit
    	/* $().validator.addMethod('correctCountFilled', function(value, element) {
    		  alert(jQuery('#login_check').text()); 
               if(jQuery('#login_check').text()=="tis is test page"){
                alert(jQuery('#login_check').text());
                return true;
            }
               else
                   {
                   alert("plese check user name first");
            	   return false;
                   }
                   
        });*/
        
        	    	
    /*    	$("#psa_registration").submit(function(psa_registration)
        		  {
        			  var s = $('#login_check').text();
        		    	alert("1");
        		    	var g = $('#gender');
        		    	var t = $('#idcountry');
        		    	alert(t);
        		    	alert(g);
        		    	alert(s);
        		    	if(s == "tis is test page")
    						return true;
        		    	else
        		    		return false;
        		    //this runs when the form validated successfully
        		    psa_registration.submit(); //submit it the form
        		  
        		});
    
     */   	
    
     $.validator.addMethod("loginRegex", function(value, element) {
         return this.optional(element) || /^[a-zA-Z]+$/i.test(value);
     }, "Username must contain only letters");
    
        	
     $.validator.addMethod("addRegex", function(value, element) {
         return this.optional(element) || /^[a-z0-9\-]+$/i.test(value);
     }, "Address must contain only letters, numbers, or dashes.");
    
    	 $("#psa_registration").validate({
    		 
    		rules: 
    		{
    			login_name:
    			{
    				required:true,
    				loginRegex:true,
    				minlength:5,
    				maxlength:20,
    			}
    	 		,
    			agency_name:
    			{
    				required:true,
    				loginRegex:true,
    				maxlength:50,
    			},
    			first_name:
    			{
    				required:true,
    				loginRegex:true,
    				maxlength:50,
    			},
    			last_name:
    			{
    				required:true,
    				loginRegex:true,
    				maxlength:50,
    			},
    			gender:"required",
    			email:
    			{
    				required:true,
    				email:true
    			},
    			address:
    			{
    				required:true,
    				addRegex:true,
    				maxlength:250,
    			},
    ----------------------------------------------
    			idcountry:
    			{
    				required:true
    			},
    ------------------------------------------------
    			
    	/*		{required:function()
    			{
    				var g = $('#idcountry');
    				alert(g);
    				alert(g.val());
    				return g.val() >= 0;
    			}},
    	*/
    			state:"required",
    			city:"required",
    			pincode:
    			{ 
    				required:true,
    				minlength:6,
    				maxlength:6,
    				digits:true,
    			},
    			phone:
    			{
    				required:true,
    				minlength:10,
    				maxlength:15,
    				digits:true,
    			},
    			mobile:
    			{
    				required:true,
    				minlength:10,
    				maxlength:15,
    				digits:true,
    			},
    			pan_number:"required",
    			user_type:"required",
    			
    			
    		},
    		
    		messages: 
    		{
    			login_name:
    				{
    					required:"Enter Name",
    				},
    			agency_name:
    			{
    				required:"Enter Agency Name",
    			},
    			first_name:
    			{
    				required:"Enter First Name",
    			},
    			last_name:
    			{
    				required:"Enter Last Name",
    			},
    			gender:"Enter Your Gender",
    			email:
    			{
    				required:"Enter Email",
    				email:"Enter Valid Email"
    			},
    			address:
    			{
    				required:"Enter Address",
    				addRegex:"Enter Valid Address"
    			},
    		------------------------------------------------------
                    	idcountry:
    			{
    				required:"Enter Country",
    			},
    			state:"Enter State Name",
    			city:"Enter City Name",
    		--------------------------------------------------------
                           pincode:
    			{
    				required:"Enter Pincode",
    			},
    			phone:
    			{
    				required:"Enter Phone Number",
    			},
    			mobile:
    			{
    				required:"Enter Mobile Number",	
    			},
    			pan_number:"Enter Pan Number",
    			user_type:"Enter User Class",
    			
    		}
    		
    	});
    });
    </script>
    
    </head>
    <body>
    	<div class="main_register">
    	<div class="header_register">
    		<span class="header_register_text">Register New PSA</span>
    		<span class="login_here"><a href="welcome.action">Login Here</a></span>
    	</div>
    	<div class="form_register">
    		<s:form method="post" action="register_psa" id="psa_registration" theme="css_xhtml" >
    			<s:hidden name="id"/>
    			<table>
    					<tr>
    						<td><s:label>Login Name</s:label> </td>
    		 				<td><s:textfield name="login_name" id="login_name"/></td>
    						<td><s:url id="simpleecho"  action="testAction"/>
    						<sj:submit id="formSubmit2"  targets="login_check" href="%{simpleecho}" button="true" onBeforeTopics="" />
    						<s:div id="login_check" name="login_check" ></s:div></td>
    					</tr>
    					<tr>
    						<td><s:label>Agency Name</s:label></td>
    						<td colspan=2><s:textfield name="agency_name" id="agency_name"/></td>
    					</tr>
    					<tr>
    						<td><s:label>First Name</s:label></td>
    						<td colspan=2><s:textfield name="first_name" id="first_name"/></td>
    					</tr>
    					<tr>
    						<td><s:label>Last Name</s:label></td>
    						<td colspan=2><s:textfield name="last_name" id="last_name"/></td>
    					</tr>
    					<tr>
    						<td><s:label>Gender</s:label></td>
    						<td colspan=2><s:select list="{'Male','Female'}" name="gender" id="gender" headerKey="" headerValue="Select Gender"/></td>
    					</tr>
    					<tr>
    						<td><s:label>Email</s:label></td>
    						<td colspan="2"><s:textfield name="email" id="email"/></td>
    					</tr>
    					<tr>
    						<td><s:label>Address</s:label></td>
    						<td colspan="2"><s:textarea name="address" id="address" cols="20" rows="6"/></td>
    					</tr>
    					<tr>
    						<td>
    							<s:label>Country</s:label></td>
    						<td colspan="2">
    						
    						<s:url id="countrylist" action="lstcountryaction"/>
               		----------------------------------------------------------------------
                             		 <sj:select 
               					list="lstcountry"
               					listKey="idcountry" 
               				 	listValue="countryname"  
               				 	href="%{countrylist}" 
               				 	headerKey="-1" 
               				 	headerValue="-select country-"
                     		 	id="idcountry"
                     		 	name="idcountry" 
                     		 	onChangeTopics="reloadstatelist,reloadcitylist" 
                     		 	onCompleteTopics="reloadstatelist,reloadcitylist" 
                            	onchange="javascript:show_textbox('idcountry','O_country');"
                              />
    -----------------------------------------------------------------------------------
    						</td>
    					</tr>
    					<tr id="O_country" style="display:none">
    						<td><s:label>Other country</s:label> </td>
    						<td colspan="2"><s:textfield name="other_country" id="other_country" /></td>
    					</tr>
    					<tr>
    						<td><s:label>State</s:label></td>
    						<td colspan="2">
    						 <s:url id="statelist" action="lststateaction"/>
                <sj:select list="lststate" listKey="idstate" listValue="statename" href="%{statelist}" formIds="psa_registration" headerKey="-1" headerValue="-select state-"
                        id="idstate"   name="idstate" reloadTopics="reloadstatelist" deferredLoading="true" onChangeTopics="reloadcitylist" onCompleteTopics="reloadcitylist" 
                           onchange="javascript:show_textbox('idstate','O_state');"/>
    						</td>
    					</tr>
    					<tr id="O_state" style="display:none">
    						<td><s:label>Other state</s:label> </td>
    						<td colspan="2"><s:textfield name="other_state" id="other_state" /></td>
    					</tr>
    					<tr>
    						<td><s:label>City</s:label> </td>
    						<td colspan="2">
    						 <s:url id="citylist" action="lstcityaction"/>
                <sj:select list="lstcity" listKey="idcity" listValue="cityname"  href="%{citylist}" formIds="psa_registration" headerKey="-1" headerValue="-select city-"
                        id="idcity"   name="idcity" reloadTopics="reloadcitylist" deferredLoading="true" onchange="javascript:show_textbox('idcity','O_city');" />
    						</td>
    					</tr>
    					<tr id="O_city" style="display:none">
    						<td><s:label>Other city</s:label> </td>
    						<td colspan="2"><s:textfield name="other_city" id="other_city" /></td>
    					</tr>
    					<tr>
    						<td><s:label>Pin Code</s:label> </td>
    						<td colspan="2"><s:textfield name="pincode" id="pincode"/></td>
    					</tr>
    					<tr>
    						<td><s:label>Phone</s:label> </td>
    						<td colspan="2"><s:textfield name="phone" id="phone"/></td>
    					</tr>
    					<tr>
    						<td><s:label>Mobile</s:label> </td>
    						<td colspan="2"><s:textfield name="mobile" id="mobile"/></td>
    					</tr>
    					<tr>
    						<td><s:label>Pan Number</s:label> </td>
    						<td colspan="2"><s:textfield name="pan_number" id="pan_number"/></td>
    					</tr>
    					<%
    					String usertype=(String)session.getAttribute(constants.Constants.SESSION_USER_TYPE);
    					if(usertype!=null)
    					if(!usertype.equals(constants.Constants.USER_ADMIN))
    					{
    					%>
    					<tr>
    						<td><s:label>User Class</s:label> </td>
    						<td colspan="2"><s:select name="user_class" id="user_class" list="{'Platinum','Gold','Silver'}" headerKey="" headerValue="Select User Class" /></td>
    					</tr>
    					
    					<tr>
    						<td><s:label>Distributor Id</s:label> </td>
    						<td colspan="2"><s:textfield name="distributor_id"/></td>
    					</tr>
    					<%} %>
    					<%
    					if(usertype!=null)
    					if(usertype.equals(constants.Constants.USER_ADMIN))
    					{
    					%>
    					<tr>
    						<td><s:label>User Type</s:label> </td>
    						<td colspan="2"><s:select name="user_class" onchange="javascript:showme();" id="user_class" list="#{'3':'Distributor','1':'Adminstrator','2':'User'}"  headerKey="0" headerValue="Select User Type" /></td>
    					</tr>
    					<tr id="showme" style="display:none">
    						<td><s:label>User Class</s:label> </td>
    						<td colspan="2"><s:select name="user_type"  id="user_class" list="{'Platinum','Gold','Silver'}" headerKey="" headerValue="Select User Class" /></td>
    					</tr>
    					
    					<tr>
    						<td><s:label>Administrator Id</s:label> </td>
    						<td colspan="2"><s:textfield name="distributor_id"/></td>
    					</tr>
    					<%} %>
    					<tr>
    						<td colspan="3"><s:submit value="Submit"  /></td>
    					</tr>
    			</table>
    		</s:form>
    	</div>
    	<div style="clear:both;"></div>
    </div>
    That's code tags...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Jquery validation in struts with ajax

    Look.
    PMing me will not get a response.
    Keep the conversation in this thread.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    ashish1987 is offline Member
    Join Date
    Apr 2012
    Location
    Delhi
    Posts
    10
    Rep Power
    0

    Default Re: Jquery validation in struts with ajax

    ok...
    If you have any solution then give me..
    that how jquery validation works with ajax plugin in struts2 ?

Similar Threads

  1. Struts + Ajax select list
    By franksniper in forum Struts
    Replies: 0
    Last Post: 04-10-2012, 11:50 PM
  2. Struts with hibernate and jquery
    By R S Reddy in forum Web Frameworks
    Replies: 1
    Last Post: 08-08-2011, 07:14 PM
  3. URL formation for Ajax request in struts.
    By fierof2 in forum Web Frameworks
    Replies: 8
    Last Post: 07-16-2010, 09:42 AM
  4. Struts 2 and Ajax drop down Example
    By priyanka.dandekar in forum Web Frameworks
    Replies: 8
    Last Post: 01-05-2010, 11:57 AM
  5. Struts validation
    By Jack in forum Web Frameworks
    Replies: 3
    Last Post: 10-06-2008, 12:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •