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>  
 
follow me on Twitter
Get Widget