Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change a DIV based on a CFINPUT

Status
Not open for further replies.

Albion

IS-IT--Management
Aug 8, 2000
517
US
I'm really unsure how to go about doing this right now so I don't have any real code. But here's what I want to do.

I have a DIV on my page

Code:
<div id="idValue">$5.00</div>

I also have a cfform

Code:
<cfform>
    <cfinput id="idCode" type="text" value="">
    <cfinput id="idButton" type="button" onclick="*Check my idCode against my mySQL database in a CFC or CFM*">
</cfform>

* The onclick above is just what I am assuming I need to do. If there is a better way then using onclick... maybe bind?

If idCode checks out in my database I want to return a value from the database then use javascript to subtract the returned value from the value contained in idValue. The problem I have is that I want this done in real time using ajax instead of having to reload the page. I kind of have a hand on bind in cfselect, but I have never used it with cfinput and a button. Is it possible? How do I get the returned coldfusion value into my javascript to change the innerHTML of idValue? Should I maybe use a locked <cfinput> or <cfdiv bind=""> instead of a <div> for idValue?

Here's my CFC as it stands. There may be some syntax errors in it as I haven't tested it yet, but you can get the jist of what I'm trying to do.

Code:
    <cffunction name="getPromoCode" access="remote" returntype="string">
    	<cfargument name="fInputPromoCode" type="string" required="true">
        
        <cfquery name="qGetPromoCode" datasource="#datasource#">
            SELECT code, value, expire
            FROM tblPromoCodes
            WHERE code = #ARGUMENTS.fInputPromoCode#;
        </cfquery>
        
        <cfif qGetPromoCode.recordCount = 0>
            <cfset myValue = "Invalid Promo Code">
        <cfelseif (DateFormat(qGetPromoCode.expire, "MM/DD/YYYY") lt DateFormat(Now(), "MM/DD/YYYY")) OR (qGetOromoCode.expire is "Infinity")>
            <cfset myValue = DollarFormat(qGetPromoCode.value)>
        <cfelse>
            <cfset myValue = "Expired Promo Code">
        </cfif>
		
        <cfreturn myValue>
    </cffunction>

I really appreciate any help I can get.

Thanks

-Al
 
you can use cfAJaxProxy
<cfajaxproxy cfc="path.to.cfc" jsclassname="nameToCallVar" />

<script>
var cfcAsAjax = new nameToCallVar();

now you can use those functions in javaScript
</script>

if(!SUCCEED) try();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top