php - JQuery Validation not working on Ajax Control....! -


hi there have problem code want validate states generated ajax response.text

here jquery state field:

$(document).ready(function () {     var form = $("#addstudentfrm");      var state = $("#state");     var stateinfo = $("#stateinfo");      state.blur(validatestates);     state.keyup(validatestates);       function validatestates() {         if (state.val() == '') {             state.addclass("error");             stateinfo.text("please select/enter state");             stateinfo.addclass("error5");             return false;         } else {             state.removeclass("error");             stateinfo.text("");             stateinfo.removeclass("error5");             return true;         }      } }); 

here php function states in respected country:

public function getallcountrystates($post){ $que = "select * ".wmx_country." code = '".$post[value1]."'"; $cres = $this->executeqry($que); $cresult = $this->getresultrow($cres); $cid = $cresult['id']; $stateobj = new admin; $rdat = $post['opr']; $rdtar = explode('.', $rdat); $res = @mysql_fetch_row(mysql_query("select * ".$rdtar['1']." id = ".$rdtar['0'])); $usts = $res['state']; $result = $stateobj->selectqry(wmx_state,"country_id=$cid",'',''); $number = $stateobj->gettotalrow($result);  if($number > 0){         $getselect ="<select name='state' id='state' class='textboxcss'>";     while($stateval = $stateobj->getresultrow($result)){                $getselect.="<option value='".$stateval[state]."'>$stateval[state]</option>"; }     $getselect.="</select>"; }else{     if($usts!=''){         $getselect = "<input type='text' name='state' id='state'class='textboxcss' value='$admnstate'/>";     } else {         $getselect = "<input type='text' name='state' id='state' class='textboxcss'/>";     } }     echo $getselect;  } 

in initial state text box getting validate

but when control comes ajax response jquery wont validate blank entries

my ajax function:

function databypost(url,objid,postdata,div_id){     var selid = objid.split('|');     var passdata = postdata;     var ajax = null;     if (window.xmlhttprequest) {        ajax=new xmlhttprequest();     } else {        ajax=new activexobject("microsoft.xmlhttp");     }    if (ajax==null) {    alert("your browser doesn't supportajax.");                              return false    } else {            ajax.open("post",url,true);        ajax.setrequestheader("content-type", "application/x-www-form-urlencoded");        ajax.onreadystatechange = function() {             if (ajax.readystate==4 || ajax.readystate=="complete"){                   alert(ajax.responsetext);                 var msg=ajax.responsetext;                 var idary = new array();                 document.getelementbyid(selid).value = msg;                 document.getelementbyid(selid).innerhtml = msg;             }        }        ajax.send(passdata);    } } //first function  function showcontent(url,arg,opr,sel_id,div_id) {     var postdata='';     var formval=arg.split('|');  if(document.getelementbyid(div_id))               document.getelementbyid(div_id).style.display='';  if(document.getelementbyid(sel_id))     document.getelementbyid(sel_id).style.display='';     for(i=1;i<=formval.length;i++)          var postdata =postdata + 'value'+i+'='+escape(formval[i-1])+'&';         postdata=postdata + 'opr='+opr;     databypost(url,sel_id,postdata,div_id);          } 

i don't know going on here without seeing actual page, few things might try:

  1. use jquery ajax since you're using it. bug-free , cross platform, , way can sure there no bugs in ajax part.

  2. i move lines "var state = $("#state"); var stateinfo = $("#stateinfo");" inside of function declare function outside of document.ready block. way can sure every time function gets called, has access variables.

  3. if ajax call replacing input you're validating, you'll need re-bind events each time ajax call finishes. jquery can using callback parameter.

i'm assuming number 3 problem, try first.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -