How to validate input tag with onchange event which check database record?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kasturi207
    New Member
    • Mar 2010
    • 1

    #1

    How to validate input tag with onchange event which check database record?

    I want to validate input (text) which i have to check with databse record is exist.
    the code something like that:-

    Code:
    <cfscript>
    function checkkp() {
    if (rscheck.recordcount NEQ 0) {
    	writeoutput("Rekod telah wujud");
    	return false;
    	}
    }
    </cfscript>
    <cfif isdefined("form.tnokp") and #from.tnokp# EQ "">
    	<cfquery name="rscheck" datasource="tryxx">
    	SELECT *
    	FROM dbo.oxy
    	WHERE NoKP = '#Form.tnokp#'</cfquery>
    </cfif>
    
    ....
    
    <input name="tnokp" type="text" id="tnokp" onchange="checkkp(this.value)" value="<cfoutput>#rsKemas.NoKP#</cfoutput>" size="16" maxlength="12" />
    i have try this. but stil update the value even the record is exist.
    Last edited by acoder; Mar 13 '10, 12:20 PM. Reason: Added [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    This is not going to work. You're trying to combine Coldfusion and JavaScript by calling a Coldfusion function via a JavaScript way.

    To solve this, either use Ajax (call the server-side code via JavaScript) or validate on the server-side only.

    PS. please use [code] tags

    Comment

    Working...