Link to home
Start Free TrialLog in
Avatar of digitalwise
digitalwise

asked on

Disable Submit Button on CFC cfdiv bind

We are checking to see if the email address is already in the system.  If it is, the system displays the message that the email is in the system but does not clear the email address.     I want to disable the submit button until they enter a valid email.     Any suggestions??  I am open to clearing the field too but every time I try that, the message goes away.

<TR class="special"><TD valign="top"><img src="images/RedStar.gif" ALT="Required" /></TD><TD class="tdheader" valign="top">Email:</TD><TD><cfinput type="text" name="email" size="40" Required="yes" message="Please enter an email for this person - check the formatting." value="#getemail.emailaddress#" maxlength="50" validate="email">

<cfdiv bind="cfc:email.checkemail({email})"
    style="font-size:14px; color:blue;" />

</TD></TR>

Open in new window


CFC

<cffunction name="checkemail" access="remote" returnType="string">
        <cfargument name="email" type="string" required="true">

        <!--- Define variables --->
        <cfset var data="">
        <cfset var result="">

        <!--- Get data --->
        <CFQUERY NAME="CheckEmail" datasource="appa_backoffice">
	select contactinfoid from cn_emailaddresses where emailaddress = '#arguments.email#'
</CFQUERY>

    
        <!--- Got it? --->
        <cfif CheckEmail.RecordCount gt 0 and len(arguments.email)>
            <cfset result="<br><em><span style='color: red;'>The email you have entered is already in the database.  Please enter a different email address.</span></em>">
            
            <CFELSE>
            <CFSET result="">
        </cfif>

        <!--- And return it --->
        <cfreturn result>
    </cffunction>

Open in new window

Avatar of Pravin Asar
Pravin Asar
Flag of United States of America image

ColdFusion has another attribute called   enabled="true|false". But this works with flash forms only.

So I think, you will be better of enable/disable the button , you could simply use jquery/javascript solution.

Here is some sample code.

<cfform name="f0">
      <cfinput type="text" name="email" onkeyup="validate()"/>
      <cfinput type="submit" name="sbtn1" value="Submit" disabled="true" />
</cfform>


<script type="text/javascript">
function validate(){
      alert (document.f0.email.value.length );
    if (document.f0.email.value.length >   0 ){
        document.f0.sbtn1.removeAttribute("disabled");
    }
    else {
        document.f0.sbtn1.setAttribute("disabled", "true");
    }
}      
</script>
Hello,

I am not sure, if you still interested in the solution.

Anyway here is a simple coldfusion bind example.

<!--- example.cfm --->

<cfform name="f0">
      <cfinput name="email" value="" type="text"/>
        <!--- Look for keyup on email field ---->
      <cfdiv bindonload="true" bind="url:ajaxRes.cfm?field={email@keyup}" style="font-size: 14px;">
      </cfdiv>
</cfform>

<!---- ajaxRes.cfm --->
<cfif isdefined ("url.field") and len(trim(url.field))>
      <input type="submit" value="Submit" name="sbtn1"/>
<cfelse>
      <cfoutput>Enter field value</cfoutput>
</cfif>
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of digitalwise
digitalwise

ASKER

Thanks as usual!