jquery - How to check the return of a JavaScript function in onchange event -
how call function inside onchange if return of previous function true, trying calling many function on onchange event, last function should call if return of previous function true. code bellow:
<input type="text" name='test' id="test" onchange="remldzero('test'); validatetest(); if(checkduplicate('test', 'url','divid')===true){ nextfunction();};" maxlength="10" required>
my jvascript checkduplicate() below
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"); } } }); }
note: if call nextfunction()
instade of return true
line, works nextfunction() brings popup browsers block popup while if call nextfunction in onchange without checking previous function works.
any soloution fix it.
here go.
html
<input type="text" name='test' id="test" onchange="remldzero('test'); validatetest(); checkduplicate('test', 'url','divid', nextfunction);" maxlength="10" required>
js
function checkduplicate(fieldid,page,msgarea,callbakfn){ 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'){ if(typeof callbakfn == "function"){ callbakfn(); } } }else{ $('#'+msgarea).html(data); $('#'+msgarea).css("display","block"); } } }); }
now nextfunction
execute after ajax request done , ur result true
.
Comments
Post a Comment