Posts

ColdFusion Script to compare a date value

<cfscript>     function isBetween(compVal, FirstVal, SecondVal)         {             var myRetVal = false;             if(FirstVal LTE SecondVal)                 {                     if(compVal GTE FirstVal AND compVal LTE SecondVal)                     RetVal = true;                 }             else                 {                     if(compVal GTE SecondVal AND compVal LTE FirstVal)                     RetVal = true;                 }                                return RetVal;         } </cfscript> <cfif #isBetween(#DateFormat(10/25/2012,"mm/dd/yyyy")#, #dateFormat(10/20/2012,'mm/dd/yyyy')#,#dateFormat(10/30/2012,'mm/dd/yyyy')# )#>     <cfoutput>The date is between the given values </cfoutput> <cfelse>     <cfoutput>The date is not between the given values </cfoutput> </cfif>

Ajax Example in coldfusion

<script type="text/javascript">     function showvalues(str)     {         var xmlhttp;            if (window.XMLHttpRequest)           {// code for IE7+, Firefox, Chrome, Opera, Safari               xmlhttp=new XMLHttpRequest();           }         else          {// code for IE6, IE5               xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");            }         xmlhttp.onreadystatechange=function()           {           if (xmlhttp.readyState==4 && xmlhttp.status==200)                 {                     document.getElementById("txtHint").innerHTML=xmlhttp.responseText;                 }         }         xmlhttp.open("GET","?city_name="+str,true);         xmlhttp.send();     } </script> <cfparam name="url.city_name" default=""> <div id="txtHint">City info will be listed here...     <cfform>         <cfselect id="city_name"

Function to Convert the first letter of a string to Capital in coldfusion

<cfform>       Enter the String: <cfinput type="text" name="strUcase">       <cfinput type="submit" name="btn_ucase" value="Submit"> </cfform> <cfif isdefined ('form.btn_ucase')>       <cfinvoke method="CapFirst" returnvariable="str1">       <cfinvokeargument name="str" value="#form.strUcase#">       </cfinvoke>       <cfoutput>Converted String is: #str1#</cfoutput> </cfif>     <cffunction name="CapFirst" returntype="string" output="false">     <cfargument name="str" type="string" required="true" />         <cfset var newstr = "" />       <cfif Len (str) GTE 1 >             <cfset newstr = UCase ( left (arguments.str,1)) & Right (arguments.str, Len (arguments.str)-1)>       </c

Query to XML and XML to query in coldfusion

<!--- Query To XML, apart from xml packet creation, this will create a new  myDoc.xml file :start---> <cfquery name="empdetails" datasource="empdetails">     select empid,empname,empage,country,state,empsalary from empdetails </cfquery> <cfxml variable="xmlPacket">       <employees>         <cfoutput query="empdetails">             <employee id="#empid#">                                   <address>                     <empname>#empname#</empname>                     <empcountry>#country#</empcountry>                     <empstate>#state#</empstate>                 </address>                 <other>                     <empage>#empage#</empage>                     <empsalary>#empsalary#</empsalary>                 </other>             </employee>         </cfoutput>     </employ

Collapsible Div

<script language="javascript"> function togglefun() {     var ele = document.getElementById("toggleText");     var text = document.getElementById("displayText");     if(ele.style.display == "block") {             ele.style.display = "none";         text.innerHTML = "[+]";       }     else {         ele.style.display = "block";         text.innerHTML = "[-]";     } } </script> <a id="displayText" href="javascript:togglefun();">[+]</a> Click here <div id="toggleText" style="display: none"><h1>Iam Collapsible Div</h1></div>

Email Validation in coldfusion

 <cfif isDefined("form.MailTo")>     <cfset valid = REFind("^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$", Trim(form.MailTo), 1) gt 0>     <cfif (form.MailTo NEQ 'Enter an email address') AND (form.MailTo NEQ '') AND (valid EQ 'YES')  >          <cfmail to = "#form.MailTo#" from = "xyz@mail.com" subject = "test"  type="text/html" >                   test             </cfmail>           <div ><h2>Email sent successfully!</h2><p>to:  <cfoutput>#form.MailTo#</cfoutput></p></div>     <cfelse>         <div ><h2>Email not sent. No valid email address supplied.</h2></div>     </cfif> </cfif> <form action = " " method="post" >         <h2>Email to:</h2> <input type = "Text" name =

Coldfusion code to remove illegal characters

<cfset s="FFFFt frgrth @!$?BNBNMJK %^&*()  LÖÖҗҢџьлÖҗҢџьлÖҗҢџьлÖҗҢџьлJLUIOUIO">  <cfset a=REReplace(s, '[^\x00-\x7F]', ' ', "ALL")>  <cfoutput>#a#</cfoutput>