title: How to check the return of a JavaScript function in onchange event
body: <p>How to call a function inside onchange if the return of previous function is true,
  what i am trying is calling many function on onchange event, but the last function should call if the return of previous function is true. my code is bellow:</p>
  
  <pre><code>&lt;input type="text" name='test' id="test" onchange="remLdZero('test'); validatetest(); if(checkDuplicate('test', 'url','divid')===true){ nextfunction();};"  maxlength="10"  required&gt;
  </code></pre>
  
  <p>my jvascript checkDuplicate() is below</p>
  
  <pre><code>function checkDuplicate(fieldId,page,msgArea){  
       var fieldVal= $('#'+fieldId).val();
       $.ajax({    
          type: "POST",
          url: page,
          data: fieldId+'='+fieldVal,    
          //dataType: "html",    
          success: function(data){
              if(data == 1){
                  $('#'+msgArea).css("display","none");
                  if(fieldId == 'test'){
                       return true;
                  }
              }else{
                  $('#'+msgArea).html(data);
                  $('#'+msgArea).css("display","block");
              } 
         }
      }); 
   }
  </code></pre>
  
  <p>Note: If i call my <code>nextfunction()</code> instade of <code>return true</code> line, it works but as my nextfunction() brings a popup then browsers block the popup while if i call the nextfunction in onchange without checking the previous function it works.</p>
  
  <p>Any soloution to fix it.</p>