views:

64

answers:

3

I Need help with ColdFusion, I want to use the CF9 ajax library, I've got <cfajaximport tags="cfform"> in my header, and included a form using <cfdiv bind="url:domainchecker.cfm"> This however replaces the entire form with the "Loading" ajax wheel then shows the results.

What I need, is for the form to submit, but the a separate results area is what gets updated (and will obviously have the ajax "loading"). I don't want the entire area to to change (does that make sense??)

A: 

I personally would use jQuery over CF Ajax functions for something beyond simple binding without too much additional JavaScript.

The provided JavaScript functions from CF are just too limited.

Since you're already used jQuery, this should be quite easy. Look at Ajax + Manipulation functions of jQuery.

Henry
Hi Henry, Thanks for the quick reply. Ive never really used ajax in coldfusion (never needed to) so could you give me an example? Or just point in the direction of a good one.Of give me an example of what you mean with jQuery (Im using jQuery on the site)Many thanks in advance
jtanner
+1  A: 

So, after much soul searching, I managed this:

<head>
...
<cfajaximport />
...
    <script>
        function handleResponse(s) {
            if(s == "AVAILABLE") {
                //rewrite span
                var domainspan = document.getElementById('DomainStatus');
                var newcontent = "Available To Register :)";
                domainspan.innerHTML = newcontent;
                var loadingspan = document.getElementById('frmGO');
                var newcontent = "<input name='' value='GO!' class='search_domain_go' type='submit' />";
                loadingspan.innerHTML = newcontent;
            } else {
                //rewrite span
                var domainspan = document.getElementById('DomainStatus');
                var newcontent = "Unavailable To Register :(";
                domainspan.innerHTML = newcontent;
                var loadingspan = document.getElementById('frmGO');
                var newcontent = "<input name='' value='GO!' class='search_domain_go' type='submit' />";
                loadingspan.innerHTML = newcontent;
            }
        }

        function CheckDomain() {
            var loadingspan = document.getElementById('frmGO');
            var newcontent = "<input name='' type='image' class='search_domain_go' src='images/ajax-loader.gif' alt='' />";
            loadingspan.innerHTML = newcontent;
            ColdFusion.Ajax.submitForm('frmDomainCheck','checkdomain.cfm',handleResponse);
        }
    </script>
...
</head>

<body>
...
        <div class="search_domain">
            <div class="search_domain_form">
            Search Your Domain Here<br />
                <form method="post" action="" onSubmit="CheckDomain();return false;" id="frmDomainCheck">
                    <input class="search_domain" name="frmURL" id="frmURL" value="Please enter your domain name here..." onfocus="if(this.value == 'Please enter your domain name here...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Please enter your domain name here...';}" type="text" />
                    <span id="frmGO"><input name="" value="GO!" class="search_domain_go" type="submit" /></span>
                <form>
            </div><!-- /# end search form -->
            <div class="domain_features">
                <ul>
                    <li><span id="DomainStatus">Type in the domain and click 'GO' to check its availability.</span></li>
                </ul>
            </div>
        </div>
...
</body>
jtanner
A: 

Keep it simple?

domainSearch.cfm

<head>
</head>

<body>
<h2 style="color:Blue">Domain search</h2>
<form name="domainSearch">
www.<input class="search_domain" name="searchString" id="frmURL" value="Please enter your domain" onfocus="if(this.value == 'Please enter your domain') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Please enter your domain';}" type="text" />.com
<font color="#FF0000"><strong>[Search]</strong></font>
</form>
<p>Enter any domain.com, (hint: try "free")</p>
<cfdiv id="resultsDiv" bind="url:searchProcessor.cfm?searchString={searchString}">
</body>
</html>

searchProcessor.cfm

<cfif IsDefined("URL.searchString")>

    <cfif URL.searchString eq "Please enter your domain">
        <cfoutput></cfoutput>   
    <cfelseif URL.searchString eq "free">
        <cfoutput>Great, #URL.searchString# is available, price $400</cfoutput>
    <cfelse>    
        <cfoutput>Sorry, #URL.searchString# is not available, try again.</cfoutput>
    </cfif>
</cfif>
Saul