Search code examples
jqueryajaxcoldfusionjquery-validation-engine

jquery validation engine always getting same response on ajax validation


I have jquery validate engine validating a form. For example the code to check mobileno is already exists in database :

MobileNumber/Login Id : 
<input type="text"  class="k-textbox validate[required,custom[phone],ajax[ajaxMobileCallCfm]]  text-input" value="" name="mobileno"  id="mobileno"/>

and call validate engine

jQuery(document).ready(function()
{
            jQuery("#register").validationEngine();

});

inline validation rules in the language file(jquery.validationEngine-en)

"ajaxMobileCallCfm": {
                    "url": "checkmobileno.cfm",
                    "alertTextOk": "* This username is available",
                    "alertText": "* This user is already taken",
                    "alertTextLoad": "* Validating, please wait"
                }

and checkmobileno.cfm

<cfset mobileno=#mobileno#>
<cfset arrayToJs = ArrayNew(2)>
  <cfif #mobileno# eq "8888888888">
    <cfset arrayToJs[1][1]="mobileno">
    <cfset arrayToJs[1][2]=true>
    <cfset arrayToJs[1][3]='This user is available'>
 <cfelse>
        <cfset arrayToJs[1][1]="mobileno">
        <cfset arrayToJs[1][2]=false>
        <cfset arrayToJs[1][3]='This user is already taken'>
  </cfif>

 <cfset theJSON = #SerializeJSON(arrayToJs)#>

<cfoutput> 
 #theJSON#
</cfoutput>

Now,checking if a mobile is available on the blur or keyup event.

when i try with number,it always show * This user is already taken.please help me where the problem.

Thanks


Solution

  • As simon said,

    <cfif mobileno eq "8888888888">
        <cfset arrayToJs[1][1]="mobileno">
        <cfset arrayToJs[1][2]=true>
        <cfset arrayToJs[1][3]='This user is available'>
    <cfelse>
    

    means that the only number available is 8888888888

    I think what you meant to say is <cfif mobileno neq "8888888888"> or whatever list of numbers is not already taken. I assume the end product would check a database and look more like <cfif not qUsedNumbers.recordCount>

    also...

    <cfset mobileno=#mobileno#> <!--- is redundant--->
    
    <!--- and you don't need so many pound signs. --->
    <cfset mobileno=#mobileno#> 
    <!--- should be --->
    <cfset mobileno=mobileno> 
    
    <cfif #mobileno# eq "8888888888"> 
    <!--- should be --->
    <cfif mobileno eq "8888888888">
    
    <cfset theJSON = #SerializeJSON(arrayToJs)#> 
    <!--- should be --->
    <cfset theJSON = SerializeJSON(arrayToJs)>