Get Widget

Thursday, July 24, 2014

Populate/change list of value in dropdown/select box via ajax

 <script>  
 /* to populate list of value in dropdown via ajax */  
 function populateSectionsList(id)  
 {  
      var idval = id;       
      var setOptTemp = "<option value='%d'>%s</option>";  
      var html = "<option value=''>-- Select --</option>";  
      $.ajax({  
           type:'post',  
           url:'http://localhost/myproject/ajaxurl',  
           data:{'id':idval, 'action':edit},  
           error:function(){  
                alert('You have error. Please try again');  
           },  
           success:function(data){  
                var optionList = $.parseJSON(data);  
                $.each(optionList, function(i, optDetails){  
                     html += setOptTemp.replace('%d', optDetails.id).replace('%s', optDetails.name);  
                });  
                $('#dropid').html(html).show();                 
           }  
      });  
 }  
 </script>  
 //myprojet/ajaxurl.php  
 <?php  
 foreach($dropListArr as $value)  
 {  
      $dataArr[] = array('id' => $value['id'], 'name' => $value['textname']);  
 }  
 ?>  

Wednesday, July 23, 2014

Check Username exist - Ajax

 <script>  
 $(document).ready(function() {  
   var isUnameExist = false;  
   //$("#frmregister").validate();  
   $("#frmregister").validate({  
     rules: {  
       username:{  
         required:true,  
         custom_usernameValidate:true  
       }       
     }  
   });  
   $.validator.addMethod('custom_usernameValidate', function(val) {  
     $.ajax({  
       type:'post',  
       url:"http://localhost/myproj/ajaxchecking.php",  
       data:{'username':val},  
       async:false,  
       success:function(data){         
         //console.log(data);  
         if(data == 'no')  
           isUnameExist = true;  
         else  
           isUnameExist = false;  
       }  
     });  
     return isUnameExist;  
   },"username already exist");  
 });  
 </script>  

jQuery Validation

 $(document).ready(function() {  
   $("#signupForm").validate({  
  rules: {  
   firstname: "required",    
   username: {  
   required: true,  
   minlength: 2  
   },  
   password: {  
   required: true,  
   minlength: 5  
   },  
   confirm_password: {  
   required: true,  
   minlength: 5,  
   equalTo: "#password"  
   },  
   email: {  
   required: true,  
   email: true  
   },  
   agree: "required"  
  },  
  messages: {  
   firstname: "Please enter your firstname",    
   username: {  
   required: "Please enter a username",  
   minlength: "Your username must consist of at least 2 characters"  
   },  
   password: {  
   required: "Please provide a password",  
   minlength: "Your password must be at least 5 characters long"  
   },  
   confirm_password: {  
   required: "Please provide a password",  
   minlength: "Your password must be at least 5 characters long",  
   equalTo: "Please enter the same password as above"  
   },  
   email: "Please enter a valid email address",  
   agree: "Please accept our policy"  
  }  
  });  
 });  
 
follow me on Twitter
Get Widget