1StopCoders

Code Examples and Industry News

ColdFusion Function to Generate a Random String

ColdFusion - 1 Comment - Created by Casey Martin: 2014-05-10 20:18:00

This ColdFusion function generates a random string:

   	
	
    
    
    
    
        
        
        
    
    


Return Multiple Variables in a ColdFusion Function

ColdFusion - 4 Comments - Created by Casey Martin: 2014-05-10 20:18:00

To return multiple variables, you will need to create a struct. In the example below, we have a struct named "data", which returns the variables "data.success" and "data.message".

 

    
     
     
    
    
    
     
 


Hello World in ColdFusion

ColdFusion - 0 Comments - Created by Casey Martin: 2014-05-10 20:17:00

ColdFusion uses tags, similar to HTML. We are using two tags below, cfset and cfoutput. Cfset sets a variable equal to a value. And cfoutput outputs the variable.



Hello World



#message#



ColdFusion Captcha with CFImage and Javascript Val

ColdFusion - 0 Comments - Created by Casey Martin: 2014-05-10 20:15:00

This is the ColdFusion code that contains a textbox and captcha image. It uses the cfimage tag to generate the captcha image.



This Javascript function converts a string to hash.
hashCode = function(str){
    var hash = 0;
    if (str.length == 0) return hash;
        for (i = 0; i < str.length; i++) {
                char = str.charCodeAt(i);
                hash = ((hash<<5)-hash)+char;
                hash = hash & hash;
        }
    return hash;
}
This Javascript function validates the entered text against the text in the image.
document.getElementById('captchaHashJS').value = hashCode('#captcha#');
function verifyCaptcha() {
    var captchaHash = document.getElementById('captcha').value;
    captchaHash = captchaHash.toUpperCase();
    captchaHash = hashCode(captchaHash);
    
    var captchaHashJS = document.getElementById('captchaHashJS').value;

    if (captchaHash != captchaHashJS) {
        alert("The value you entered for the captcha is incorrect.");
        window.setTimeout(function () { 
            document.getElementById('captcha').focus(); 
        }, 0); 
        return false;
    }
}


Alternating Row Colors with ColdFusion

ColdFusion - 0 Comments - Created by Casey Martin: 2014-05-10 20:14:00

Alternating row colors in ColdFusion is easy. The magic happens with one line of code in the cfoutput of the query.


         SELECT FirstName, LastName
         FROM Users



    
FirstName LastName
#FirstName# #LastName#