IT Community - Software Programming, Web Development and Technical Support

ColdFusion Tips & Tricks

This is a discussion on ColdFusion Tips & Tricks within the ColdFusion Programming forums, part of the Web Development category; javascript: Moving items from one multi-select box to another Seems like everybody tends to shy away from this in ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ColdFusion Programming

Register FAQ Members List Calendar Mark Forums Read
  #31  
Old 02-21-2008, 12:26 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Javascript: Moving items from one multi-select box to ano

javascript: Moving items from one multi-select box to another


Seems like everybody tends to shy away from this in websites - moving an item from one multi-select box to another. I had to perform the same task so I thought I'd share the Javascript routines that made it easy.

What you need is two select boxes (of course) and two normal buttons to kick off a javascript routine. Both buttons call the same routine but specify the select boxes in reverse order.

Syntax: SelectMoveRows(<source select box>,<destination select box>);
Example: SelectMoveRows(document.Example.Features,document. Example.FeatureCodes);

The way it works is that it will scan through the values of the source select box and if any rows that are selected, it will add it to the bottom of the destination select box and then remove it from the source select box. Once it has scanned through the source select box, it will call a second function called "SelectSort" in order to sort the values of the destination select box using a simple bubble sort. Note that the sort is a ASCII sort so if you have three rows with the values of "Row 1", "Row 2", and "Row 10", "Row 10" will be sorted between "Row 1" and "Row 2".

If you look at the example HTML attached below, both the Add and Remove buttons call the same Javascript function, however, the source and destination fields are reversed for the Remove button. (Make sure they're buttons, not submit buttons!)

This Javascript routine works for Internet Explorer 5+, Netscape 4.7, and Netscape 7.0

Example HTML/CFML code:


Code:
<html>
<head>
<title>Multi-list copy example</title>
<body>
<script language="Javascript">
function SelectMoveRows(SS1,SS2)
{
    var SelID='';
    var SelText='';
    // Move rows from SS1 to SS2 from bottom to top
    for (i=SS1.options.length - 1; i>=0; i--)
    {
        if (SS1.options[i].selected == true)
        {
            SelID=SS1.options[i].value;
            SelText=SS1.options[i].text;
            var newRow = new Option(SelText,SelID);
            SS2.options[SS2.length]=newRow;
            SS1.options[i]=null;
        }
    }
    SelectSort(SS2);
}
function SelectSort(SelList)
{
    var ID='';
    var Text='';
    for (x=0; x < SelList.length - 1; x++)
    {
        for (y=x + 1; y < SelList.length; y++)
        {
            if (SelList[x].text > SelList[y].text)
            {
                // Swap rows
                ID=SelList[x].value;
                Text=SelList[x].text;
                SelList[x].value=SelList[y].value;
                SelList[x].text=SelList[y].text;
                SelList[y].value=ID;
                SelList[y].text=Text;
            }
        }
    }
}
</script>
<form name="Example">
<table border="0" cellpadding="3" cellspacing="0">
    <tr>
        <td>
            <select name="Features" size="9" MULTIPLE>
                <option value="2">Row 2</option>
                <option value="4">Row 4</option>
                <option value="5">Row 5</option>
                <option value="6">Row 6</option>
                <option value="7">Row 7</option>
                <option value="8">Row 8</option>
                <option value="9">Row 9</option>
            </select>
        </td>
        <td align="center" valign="middle">
            <input type="Button" value="Add >>" style="width:100px" onClick="SelectMoveRows(document.Example.Features,document.Example.FeatureCodes)"><br>
            <br>
            <input type="Button" value="<< Remove" style="width:100px" onClick="SelectMoveRows(document.Example.FeatureCodes,document.Example.Features)">
        </td>
        <td>
            <select name="FeatureCodes" size="9" MULTIPLE>
                <option value="1">Row 1</option>
                <option value="3">Row 3</option>
            </select>
        </td>
    </tr>
</table>
</form>

</body>
</html>
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #32  
Old 02-21-2008, 12:28 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Javascript: Smart Select Lists

javascript: Smart Select Lists


The nice thing about select lists is that if you click on the list and then hit a key, the list will jump down to the letter you selected. So if you have a list with a thousand entries, you can hit "M" to jump to the first entry that starts with "M" (case insensitive). The problem with this is that if you have a hundred entries that start with "M", you still have to scroll down and search for the value you want.

To provide a method of allowing the user to type in a value and have the select list auto-select the first matching value, you need to provide a text field above the select box. Note that the Javascript below will only work with single-select lists, not multiple-select lists.

The first example below will loop over the entire list to search for a matching string and is ideal for short lists for simplicity.

The second example below is for lists that contain hundreds or even thousands of values. It creates an array, one position for each letter of the alphabet, that stores the location of it's first occurrence. It'll also exit the search if it's searching for strings that start with a specified letter and it comes to a list option that starts with a letter that comes later in the alphabet. For example, if the user types "Eb" and there is no list entry that starts with "Eb", it'll stop searching when it hits a list entry that starts with "F".

Both of the examples will perform a case insensitive match.

Note: For best results, all selection lists should be sorted alphabetically.

Example HTML/CFML code:


Example 1, for short select lists
Code:
<script language="Javascript">
function SchKey(obj)
{
  // event.keyCode holds the ASCII value of the key pressed
  var k=event.keyCode;
  // Only execute if user presses letter, number, or space
  if ((k>=65 && k<=90) || (k>=95 && k<=122) || (k>=48 && k<=57) || k==32)
  {
    var SL=document.MyForm.SelectList;
	var SearchStr=document.MyForm.SearchKey.value;
    for (i=0; i<SL.options.length; i++)
    {
      if (SL.options[i].text.toUpperCase().substr(0,SearchStr.length)==SearchStr.toUpperCase())
      {
        // We have  a match - highlight it and set the index so the loop will end
        SL.selectedIndex=i;
        i=SL.length + 1;
      }
    }
  }
  return true;
}
</script>
<form name="MyForm">
<input type="Text" name="SearchKey" onKeyUp="return SchKey()"><br>
<select name="SelectList" size="12">
  <option>a</option><option>b</option><option>ba</option>
  <option>c</option><option>d</option><option>da</option>
  <option>e</option><option>f</option><option>fa</option>
  <option>g</option><option>h</option><option>ha</option>
  </select>
</form>

================================================== ===================

Example 2, for very long select lists
Code:
<script language="Javascript">
var StrInit=0;
var StrIdx=new Array(0);
StrIdx[0]=0;
for (i=1; i<=25; i++){StrIdx[i]=-1;}

function SchKey(obj)
{
  // event.keyCode holds the ASCII value of the key pressed
  var k=event.keyCode;
  // Only execute if user presses letter, number, or space
  if ((k>=65 && k<=90) || (k>=95 && k<=122) || (k>=48 && k<=57) || k==32)
  {
    if (StrInit == 0) InitStrArray();
    var SL=document.MyForm.SelectList;
    var SearchStr=document.MyForm.SearchKey.value;
    var SearchKey=SearchStr.toUpperCase().charAt(0);
    var StartAt=StrIdx[SearchStr.toUpperCase().charCodeAt(0) - 65];
    for (i=StartAt; i<SL.options.length; i++)
    {
      if (SL.options[i].text.toUpperCase().substr(0,SearchStr.length)==SearchStr.toUpperCase())
      {
        // We have  a match - highlight it and set the index so the loop will end
        SL.selectedIndex=i;
        i=SL.length + 1;
      }
      if (i < SL.length && SL.options[i].text.toUpperCase().charAt(0) != SearchKey)
      {
        // We've passed the letter we're looking for, means not found, exit loop
        i=SL.length + 1;
      }
    }
  }
  return true;
}
function InitStrArray()
{
  var SL=document.MyForm.SelectList;
  var c=0;
  for (i=0; i<SL.options.length; i++)
  {
    c=SL.options[i].text.toUpperCase().charCodeAt(0);
    if (c >= 65 && c <= 90)
    {
      c=c - 65;
      if (StrIdx[c] == -1) StrIdx[c]=i;
    }
  }
  // Copy any undefined entries to match the preceding entry
  for (i=1; i<=25; i++)
  {
    if (StrIdx[i] == -1) StrIdx[i]=StrIdx[i - 1];
  }
  // Set the flag indicating we've built the index
  StrInit=1;
  return;
}
</script>
<form name="MyForm">
<input type="Text" name="SearchKey" onKeyUp="return SchKey()"><br>
<select name="SelectList" size="12">
  <option>b</option><option>d</option><option>f</option>
  <option>h</option><option>hn</option><option>hd</option>
  </select>
</form>
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #33  
Old 02-21-2008, 12:29 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Javascript: Trimming form fields

javascript: Trimming form fields



This function simulates the CF Trim( ) function.


Example HTML/CFML code:
Code:
function trim(thisString){
	var newString = thisString;
	while (newString.charCodeAt(0) < 33)
	{
		newString = newString.substring(1,newString.length);
	}
	
	while (newString.charCodeAt(newString.length - 1) < 33)
	{
		newString = newString.substring(0, newString.length - 1);
	}
	return newString;
}
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #34  
Old 02-21-2008, 12:30 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Smile ColdFusion Tips & Tricks - Javascript: Validating Integer and Float fields

javascript: Validating Integer and Float fields


Here's a set of Javascript functions that will allow you to check to see if text elements on your form contain valid numeric values. Optionally, you can allow the value to contain commas or be a negative number. You can validate all of your integer fields with one Javascript function call.

ValidateIntegerFields(thisform,Fields,Desc,AllowCo mma,AllowNeg)
ValidateFloatFields(thisform,Fields,Desc,AllowComm a)

thisform is the form reference, Fields will contain a pipe delimited list of field names (case sensative), Desc is also a pipe delimited list of field descriptions, AllowComma - true or false, AllowNeg - true or false. If you specify AllowComma = true, all it does is to simply allow the comma, it does not validate the correct placement of the comma. Recomend that you strip out all commas in your form action page.

If the user does not specify a value at all, the function will return true (okay). Use the ValidateRequiredFields( ) function to check to see if form elements actually has a value.

Example HTML/CFML code:
Code:
<script language="Javascript">
function trim(thisString){
	var newString = thisString;
	while (newString.charCodeAt(0) < 33)
	{
		newString = newString.substring(1,newString.length);
	}
	
	while (newString.charCodeAt(newString.length - 1) < 33)
	{
		newString = newString.substring(0, newString.length - 1);
	}
	return newString;
}

function ValidateIntegerFields(thisform,Fields,Desc,AllowComma,AllowNeg)
{
	var tmpVal='';
	var FieldArray=new Array();
	var DescArray=new Array();
	var tmp=0;
	var tmpMsg='';
	// Create array for Field list
	tmpVal=Fields;
	do
	{
		tmp=tmpVal.indexOf('|');
		if (tmp == -1)
		{
			if (tmpVal != '')
			{
				FieldArray[FieldArray.length]=tmpVal;
				tmpVal='';
			}
		} else {
			FieldArray[FieldArray.length]=tmpVal.substring(0,tmp);
			tmpVal=tmpVal.substring(tmp + 1);
		}
	}
	while (tmpVal != '');
	// Create array for Desc list
	tmpVal=Desc;
	do
	{
		tmp=tmpVal.indexOf('|');
		if (tmp == -1)
		{
			if (tmpVal != '')
			{
				DescArray[DescArray.length]=tmpVal;
				tmpVal='';
			}
		} else {
			DescArray[DescArray.length]=tmpVal.substring(0,tmp);
			tmpVal=tmpVal.substring(tmp + 1);
		}
	}
	while (tmpVal != '');
	// Check to see if passed strings are of equal length
	if (FieldArray.length != DescArray.length)
	{
		alert('Fatal error: ValidateInteger - Passed lists do not have the same length');
		return false;
	}
	// Validate fields
	for (i=0; i<FieldArray.length;i++)
	{
		tmpMsg='';
		eval('tmpVal=thisform.' + FieldArray[i] + '.value');
		if (!AllowNeg && tmpVal < 0)
		{
			alert(DescArray[i] + ' may not be a negative value.');
			// Fix for IWOF NSO
			if (FieldArray[i].substring(0,4) == 'Hold')
			{
				eval('thisform.Qty_' + FieldArray[i].substring(5) + '.select()');
			} else {
				eval('thisform.' + FieldArray[i] + '.select()')
			}
			return false;
		}
		if (!ValInt(tmpVal,AllowComma))
		{
			if (AllowComma != 1 && tmpVal.indexOf(',') != -1) tmpMsg=' without commas';
			if (tmpVal.indexOf('.') != -1) tmpMsg=' (no decimal fraction)';
			alert(DescArray[i] + ' must be an integer value' + tmpMsg + '.');
			// Fix for IWOF NSO
			if (FieldArray[i].substring(0,4) == 'Hold')
			{
				eval('thisform.Qty_' + FieldArray[i].substring(5) + '.select()');
			} else {
				eval('thisform.' + FieldArray[i] + '.select()')
			}
			return false;
		}
	}
	return true;
}




function ValidateFloatFields(thisform,Fields,Desc,AllowComma)
{
	var tmpVal='';
	var FieldArray=new Array();
	var DescArray=new Array();
	var tmp=0;
	var tmpMsg='';
	// Create array for Field list
	tmpVal=Fields;
	do
	{
		tmp=tmpVal.indexOf('|');
		if (tmp == -1)
		{
			if (tmpVal != '')
			{
				FieldArray[FieldArray.length]=tmpVal;
				tmpVal='';
			}
		} else {
			FieldArray[FieldArray.length]=tmpVal.substring(0,tmp);
			tmpVal=tmpVal.substring(tmp + 1);
		}
	}
	while (tmpVal != '');
	// Create array for Desc list
	tmpVal=Desc;
	do
	{
		tmp=tmpVal.indexOf('|');
		if (tmp == -1)
		{
			if (tmpVal != '')
			{
				DescArray[DescArray.length]=tmpVal;
				tmpVal='';
			}
		} else {
			DescArray[DescArray.length]=tmpVal.substring(0,tmp);
			tmpVal=tmpVal.substring(tmp + 1);
		}
	}
	while (tmpVal != '');
	// Check to see if passed strings are of equal length
	if (FieldArray.length != DescArray.length)
	{
		alert('Fatal error: ValidateFloat - Passed lists do not have the same length');
		return false;
	}
	// Validate fields
	for (i=0; i<FieldArray.length;i++)
	{
		tmpMsg='';
		eval('tmpVal=thisform.' + FieldArray[i] + '.value');
		if (!ValFloat(tmpVal,AllowComma))
		{
			if (AllowComma != 1 && tmpVal.indexOf(',') != -1) tmpMsg=' without commas';
			alert(DescArray[i] + ' must be a numeric value' + tmpMsg + '.');
			eval('thisform.' + FieldArray[i] + '.focus()')
			return false;
		}
	}
	return true;
}





function ValInt(ObjectValue,AllowComma)
{
	// Used internally by VaidateInteger

	//Returns true if value is a number or is NULL
	//otherwise returns false	
	
	if (ObjectValue.length == 0) return true;
	
	//Returns true if value is an integer defined as
	//   having an optional leading + or -.
	//   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;
	
	//The first character can be + -  blank or a digit.
	check_char = ObjectValue.indexOf(decimal_format)
	//Was it a decimal?
	if (check_char < 1) return ValFloat(ObjectValue,AllowComma); else return false;
}

function ValFloat(ObjectValue,AllowComma)
{
	// Used Internally by ValidateInt, ValidateFloat

	//Returns true if value is a number or is NULL
	//otherwise returns false	
	
	if (ObjectValue.length == 0) return true;
	
	//Returns true if value is a number defined as
	//   having an optional leading + or -.
	//   having at most 1 decimal point.
	//   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	if (AllowComma == 1) number_format=number_format + ',';
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
	
	//The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(ObjectValue.charAt(0))
	//Was it a decimal?
	if (check_char == 1)
		decimal = true;
	else if (check_char < 1)
		return false;
	
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < ObjectValue.length; i++)
	{
		check_char = number_format.indexOf(ObjectValue.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits) trailing_blank = true;
			// ignore leading blanks
		}
		else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
	//All tests passed, so...
	return true
}
function SubmitForm()
{
	if (!ValidateIntegerFields(document.Test,'Integer','Integer Field',false,false)) return false;
	if (!ValidateIntegerFields(document.Test,'IntegerNeg','Integer Field with negative values allowed',false,true)) return false;
	if (!ValidateIntegerFields(document.Test,'IntegerComma','Integer Field with commas allowed',true,false)) return false;

	if (!ValidateFloatFields(document.Test,'Float','Float Field',false,false)) return false;
	if (!ValidateFloatFields(document.Test,'FloatComma','Float Field with commas allowed',true,false)) return false;
	alert('All is okay!');
}
</script>

<form name="Test">
Integer: <input type="Text" name="Integer" value=""><br>
Allow negative Integer: <input type="Text" name="IntegerNeg" value=""><br>
Integer with comma: <input type="Text" name="IntegerComma" value=""><br>
Float: <input type="Text" name="Float" value=""><br>
Float with comma: <input type="Text" name="FloatComma" value=""><br>
<input type="Button" value="Go!" onClick="SubmitForm()">
</form>
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #35  
Old 02-21-2008, 12:31 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Smile ColdFusion Tips & Tricks -Locking down the URL

Locking down the URL

With CF 5+, you can create custom functions that work like the built-in functions. These two functions here allow you to identify if the URL has been altered in any way and to prevent a user from sharing the URL with another user (the check will fail if the IP address of the remove user is different). The way it works is that it appends a hash value to the end of the URL that is built off of the domain name of the website, the user's IP address, the current script being executed (as shown on the URL), and the URL parameters.

The cleanest way to implement this code is to create a template that contains all of your custom functions and include it in the Application.cfm template or whatever templates you need to have the functions available.

To "lock down" the URL, simply pass the URL parameters to the URLHash function.

Before
Code:
<a href="index.cfm?Action=Edit&id=353">Edit Employee</a>
After
Code:
<a href="index.cfm?#URLHash("Action=Edit&id=353")#">Edit Employee</a>
On the next page, you can check to see if the URL has been modified in any way by calling the URLCheckHash function. If it fails (returns "0"), redirect them to the home page.
Code:
<CFIF NOT URLCheckHash()>
  <CFLOCATION URL="/index.cfm">
</CFIF>
If you need to call the encode function from inside a CF Tag, simply set a variable to the contents of the URL string and pass the variable to the function.

Code:
<CFSET URL="Action=View+Employee&id=322">
<CFLOCATION URL="index.cfm?#URLHash(URL)#">


Example HTML/CFML code:

<cfscript>
function URLHash(URLValue)
{
  var HashData=cgi.Server_Name & cgi.Remote_Addr & cgi.Script_Name & URLValue;
  var out=URLValue & "&hash=" & LCase(Hash(HashData));
  return out;
}

function URLCheckHash()
{
  var tmp=CGI.Query_String;
  var listL=0;
  var loop=0;
  var URLVar="";
  var HashData="";
  if (IsDefined("URL.Hash"))
  {
    if (URL.Hash NEQ "")
    {
      tmp=CGI.Query_String;
      listL=ListLen(tmp,"&");
      URLVar=ListGetAt(tmp,ListL,"&");
      if (Left(UCase(URLVar),5) EQ "HASH=")
      {
        tmp=ListDeleteAt(tmp,ListL,"&");
      }
      HashData=cgi.Server_Name & cgi.Remote_Addr & cgi.Script_Name & tmp;
      if (URL.Hash EQ Hash(HashData))
      {
        return "1";
      } else {
        return "0";
      }
    } else {
      return "0";
    }
  } else {
    return "0";
  }
}
</cfscript>
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #36  
Old 02-21-2008, 12:33 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Managing Application and Session variables

Managing Application and Session variables

Ever wanted to muck around with your application and session variables without having to hard code stuff in your programs? Attached are two programs that will allow you to view, edit, delete and/or add session and application variables.

The first program, EditSession.cfm, displays the variables. The 2nd program actually performs the edits and then redirects back to the 1st program to display the new values.

You can do one of two things to your application/session variables: You can delete a variable or you can edit/add a variable. If you wanted to delete a variable to see how your program would react, set the checkbox next the variable in question and click on the button labeled "Delete Selected Variables". If you wanted to edit the values of existing variables, type in the changes you want and click on the "Update Application/Session Variables" button. At the bottom of both the application and session variable listing there are two blank text boxes where you can enter a new variable name and it's value (if any). Clicking the Update button creates the variables.

Note that application/session structures, queries, and arrays will be displayed but you will not be able to edit the contents.

Simply save the code below for the two programs to your project directory and point your browser to SessionEdit.cfm


Example HTML/CFML code:


================================================== =================================================
SessionEdit.cfm
================================================== =================================================
Code:
<cfsetting enablecfoutputonly="Yes" showdebugoutput="No">

<!---

Session/Application variable edit, by John Bartlett (jbartlett@nxs.net)

--->

<!--- Fetch the session and application variables --->
<CFLOCK timeout="2" throwontimeout="No" name="EditApp" type="EXCLUSIVE">
<CFSET sess=ListSort(StructKeyList(session,","),"TextNoCase","ASC",",")>
<CFSET app=ListSort(StructKeyList(application,","),"TextNoCase","ASC",",")>
</CFLOCK>

<CFOUTPUT>
<html>
<head>
<title>Application/Session variable edit</title>
<META HTTP-EQUIV="expires" CONTENT="Fri, 1 Jan 1990 00:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="cache-control" VALUE="no-cache, no-store, must-revalidate">
</head>
<body bgcolor="##FFFFFF" text="##000000">
<form method="POST" action="SessionEditUpdate.cfm">
<font face="Arial" size="4"><b>Application Variables</b></font>
<table border="1" cellpadding="3" cellspacing="0">
</CFOUTPUT>

<CFSET EditApp="">
<CFSET EditSess="">

<!--- Display all application variables --->
<CFLOOP index="var" list="#app#">
  <CFLOCK timeout="2" throwontimeout="No" name="EditApp" type="EXCLUSIVE">
  <CFSET tmp=Evaluate("application.#var#")>
  </CFLOCK>
  <CFSET out=tmp>
  <CFSET edit=1>
  <CFIF IsArray(tmp)>
    <CFSET out="[Array]">
    <CFSET edit=0>
  <CFELSEIF IsQuery(tmp)>
    <CFSET out="[Query]">
    <CFSET edit=0>
  <CFELSEIF IsStruct(tmp)>
    <CFSET out="[Structure]">
    <CFSET edit=0>
  </CFIF>
  <CFOUTPUT>
  <tr>
    <td><input type="Checkbox" name="app" value="#var#"></td>
    <td>#LCase(var)#</td>
    <CFIF edit EQ 1>
      <CFSET EditApp=ListAppend(EditApp,var)>
      <td>
        <input type="Text" name="i_app_#var#" value="#out#" size="50">
        <input type="Hidden" name="o_app_#var#" value="#out#">
      </td>
    <CFELSE>
      <td>#out#</td>
    </CFIF>
  </tr>
  </CFOUTPUT>
</CFLOOP>

<CFOUTPUT>
  <tr>
    <td>&nbsp;</td>
    <td><input type="Text" name="NewApp" size="15"></td>
    <td><input type="Text" name="NewAppVal" size="50"></td>
  </tr>
</table>
<br><br>
<font face="Arial" size="4"><b>Session Variables</b></font>
<table border="1" cellpadding="3" cellspacing="0">
</CFOUTPUT>

<!--- Display all session variables --->
<CFLOOP index="var" list="#sess#">
  <CFLOCK timeout="2" throwontimeout="No" name="EditApp" type="EXCLUSIVE">
  <CFSET tmp=Evaluate("session.#var#")>
  </CFLOCK>
  <CFSET out=tmp>
  <CFSET edit=1>
  <CFIF IsArray(tmp)>
    <CFSET out="[Array]">
    <CFSET edit=0>
  <CFELSEIF IsQuery(tmp)>
    <CFSET out="[Query]">
    <CFSET edit=0>
  <CFELSEIF IsStruct(tmp)>
    <CFSET out="[Structure]">
    <CFSET edit=0>
  </CFIF>
  <CFOUTPUT>
  <tr>
    <td><input type="Checkbox" name="sess" value="#var#"></td>
    <td>#LCase(var)#</td>
    <CFIF edit EQ 1>
      <CFSET EditSess=ListAppend(EditSess,var)>
      <td>
        <input type="Text" name="i_sess_#var#" value="#out#" size="50">
        <input type="Hidden" name="o_sess_#var#" value="#out#">
      </td>
    <CFELSE>
      <td>#out#</td>
    </CFIF>
  </tr>
  </CFOUTPUT>
</CFLOOP>

<CFOUTPUT>
  <tr>
    <td>&nbsp;</td>
    <td><input type="Text" name="NewSess" size="15"></td>
    <td><input type="Text" name="NewSessVal" size="50"></td>
  </tr>
</table>
<br>
<input type="Hidden" name="EditApp" value="#EditApp#">
<input type="Hidden" name="EditSess" value="#EditSess#">
<input type="Submit" name="submit" value="Delete Checked Variables">
<input type="Submit" name="submit" value="Update Application/Session Variables">
</form>
</body>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
</head>
</html>
</CFOUTPUT>
================================================== =================================================
SessionEditUpdate.cfm
================================================== =================================================
Code:
<CFPARAM name="form.sess" default="">
<CFPARAM name="form.app" default="">
<CFPARAM name="form.EditApp" default="">
<CFPARAM name="form.EditSess" default="">
<CFPARAM name="form.submit" default="">

<CFIF submit EQ "Delete Checked Variables">
  <CFIF Len(sess) GT 0>
    <CFLOOP index="var" list="#sess#">
      <CFLOCK timeout="2" throwontimeout="No" name="EditApp" type="EXCLUSIVE">
      <CFSET tmp=StructDelete(session,var)>
      </CFLOCK>
    </CFLOOP>
  </CFIF>

  <CFIF Len(app) GT 0>
    <CFLOOP index="var" list="#app#">
      <CFLOCK timeout="2" throwontimeout="No" name="EditApp" type="EXCLUSIVE">
      <CFSET tmp=StructDelete(application,var)>
      </CFLOCK>
    </CFLOOP>
  </CFIF>

<CFELSEIF submit EQ "Update Application/Session Variables">
  <CFLOOP index="var" list="#Form.EditApp#" delimiters=",">
    <CFSET old=Evaluate("Form.o_app_#var#")>
    <CFSET new=Evaluate("Form.i_app_#var#")>
    <CFIF old NEQ new>
      <cflock timeout="2" throwontimeout="No" name="EditApp" type="EXCLUSIVE">
      <CFSET tmp=StructUpdate(application,var,new)>
      </CFLOCK>
    </CFIF>
  </CFLOOP>
  <CFLOOP index="var" list="#Form.EditSess#" delimiters=",">
    <CFSET old=Evaluate("Form.o_sess_#var#")>
    <CFSET new=Evaluate("Form.i_sess_#var#")>
    <CFIF old NEQ new>
      <cflock timeout="2" throwontimeout="No" name="EditApp" type="EXCLUSIVE">
      <CFSET tmp=StructUpdate(session,var,new)>
      </CFLOCK>
    </CFIF>
  </CFLOOP>
  <CFIF Len(Trim(form.NewApp)) GT 0>
    <cflock timeout="2" throwontimeout="No" name="EditApp" type="EXCLUSIVE">
    <CFSET tmp=StructInsert(application,form.NewApp,form.NewAppVal,"True")>
    </CFLOCK>
  </CFIF>
  <CFIF Len(Trim(form.NewSess)) GT 0>
    <CFLOCK timeout="2" throwontimeout="No" name="EditApp" type="EXCLUSIVE">
    <CFSET tmp=StructInsert(session,form.NewSess,form.NewSessVal,"True")>
    </CFLOCK>
  </CFIF>
</CFIF>

<CFLOCATION URL="SessionEdit.cfm">
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #37  
Old 02-21-2008, 12:34 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Monitoring a webserver

Monitoring a webserver


If you have multiple webservers (ie: development and production), you can have one webserver monitoring the other webserver and if either the webserver software or Cold Fusion goes down, to notify whomever via Email that it's down. If you have an Email address that pipes all email to a pager, you can be notified anywhere if your server goes screaming into the night.

Attached are the templates you will need to create on both the webserver being monitored and the webserver doing the monitoring.

These templates will only work if you are not using SSL (https) since Cold Fusion can't seem to read in these sites thanks to a Microsoft bug.

Create a directory called "WebserverTests" or whatever you desire (but be sure to change it in the code) on both webservers and place everything in it. Once you can get it working on an on-demand basis, add an entry in the CF Administrator's Schedulers page to kick it off every 15 minutes or so from 00:15:00 to 23:45:00 every day. The program will first fetch an HTML document which will verify if the Webserver is responding. Then it will fetch a Cold Fusion program which will test to see if CF is responding.


Example HTML/CFML code:


Test.cfm, located on webserver being monitored (1 line)
=====
<CFOUTPUT>OK</CFOUTPUT>
=====

Test.html, located on webserver being monitored (1 line)
=====
OK
=====

WebserverTest.cfm, located on webserver doing the monitoring
=====
Code:
<CFSET SystemName="Production">  <!--- The system being checked --->
<CFSET EmailList="someone@somewhere.com,somepager@somewhere.com">
<CFSET cf=1>
<CFSET iis=0>

<cfhttp url="http://www.mydomain.com/WebserverTests/Test.html"
        method="GET"
        resolveurl="false"
        timeout="15"></cfhttp>
<CFOUTPUT>IIS Server: #cfhttp.filecontent#<br></CFOUTPUT>
<CFIF cfhttp.FileContent CONTAINS "OK">
  <cfhttp url="http://www.mydomain.com/WebserverTests/Test.cfm"
          method="GET"
          resolveurl="false"
          timeout="15"></cfhttp>
          <CFOUTPUT>Cold Fusion Server: #cfhttp.filecontent#<br></CFOUTPUT>
  <CFIF cfhttp.FileContent CONTAINS "OK">
    <CFSET cf=0>
  </CFIF>
<CFELSE>
  <CFSET iis=1>
</CFIF>

<CFSET mess="">
<CFIF iis EQUAL 1>
  <CFSET mess="The #SystemName# Web Server is not responding.">
<CFELSEIF cf EQUAL 1>
  <CFSET mess="The #SystemName# Cold Fusion server is not responding.">
</CFIF>

<CFIF mess NOT EQUAL "">
  <CFMAIL TO="#EmailList#"
          FROM="Cold Fusion Server"
          SUBJECT="(#SystemName#) Webserver Tests failed">#mess#

Message received:
#cfhttp.filecontent#
</CFMAIL>
  <CFOUTPUT><h1>#mess#</h1></CFOUTPUT>
<CFELSE>
  <CFOUTPUT><font face="Arial" size="6">The #SystemName# servers are responding.</font></CFOUTPUT>
</CFIF>
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #38  
Old 02-21-2008, 12:36 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Multiple dynamic drop-down selection boxes

Multiple dynamic drop-down selection boxes



This code allows the user to dynamically populate the contents of a select box based on a selection from a previous select box.
Create two select boxes. The first will have selections visible. The second does not have any selections visible UNTIL a selection is made from the first. Use a number of '&nbsp;' characters to create a place holder in the second select box. When a selection is made from the first select box, the 'onChange' event makes a call to a javascript function. This function will use the selectedIndex from the first select box to dynamically populate the second, based on that selectedIndex. The choices for the second select box are effectively 'stored' in the javascript function.

Try it and the mechanism will reveal itself to you.

Example HTML/CFML code:

Code:
<html>
<head>
 <title>Dynamic JS Dropdowns</title>
 <script language="JavaScript1.2">
 function whichColour(obj){

  if(obj.selectBorder.selectedIndex == 1){
   obj.selectColour.length=4
   obj.selectColour.options[0].value="Tracy"
   obj.selectColour.options[0].text="Tracy"
   obj.selectColour.options[1].value="Herta"
   obj.selectColour.options[1].text="Herta"
   obj.selectColour.options[2].value="Andretti"
   obj.selectColour.options[2].text="Andretti"
   obj.selectColour.options[3].value="Franchitti"
   obj.selectColour.options[3].text="Franchitti"
   obj.selectColour.selectedIndex = 0
   return
   }
   obj.selectColour.length=2
   obj.selectColour.options[0].value="Papis"
   obj.selectColour.options[0].text="Papis"
   obj.selectColour.options[1].value="Brack"
   obj.selectColour.options[1].text="Brack"
   obj.selectColour.selectedIndex = 0
  }
 </script>
</head>

<body>
<form>
 <table>

   <tr>
    <td>OPTIONS<br>
     <select name="selectBorder" onchange="whichColour(this.form)">
      <option>-- select --</option>
      <option value="A">A</option>
      <option value="B">B</option>
     </select>

     <select name="selectColour" onchange="whichColour(this.form)">

<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>

      <option></option>
      <option></option>
      <option></option>
      <option></option>
      <option></option>
      <option></option>
     </select>

    </td>
   </tr>

 </table>
</form>
</body>
</html>
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #39  
Old 02-21-2008, 12:37 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Next n Records

Next n Records

If you've ever been disgrunted with getting a Next n thing working, take a look below and copy-n-paste what you need.

Example HTML/CFML code:


Code:
<CFPARAM name="start" default="1"> <!--- Start displaying with record 1 if not specified via url --->
<CFPARAM name="disp" default="5">  <!--- Number of records to display on a page --->

<!--- Fetch records --->
<CFQUERY name="data" datasource="MyDB">
  SELECT MyField
  FROM MyDB
  ORDER BY MyField
</CFQUERY>

<CFSET end=Start + disp>
<CFIF start + disp GREATER THAN data.RecordCount>
  <CFSET end=999>
<CFELSE>
  <CFSET end=disp>
</CFIF>

<CFOUTPUT query="data" startrow="#start#" maxrows="#end#">
  #CurrentRow#. #MyField#<br>
</CFOUTPUT>
<CFOUTPUT>
<br>

<table border="0" cellpadding="10"><tr>
<!--- Display prev link --->
<CFIF start NOT EQUAL 1>
  <CFIF start GTE disp>
    <CFSET prev=disp>
    <CFSET prevrec=start - disp>
  <CFELSE>
    <CFSET prev=start - 1>
    <CFSET prevrec=1>
  </CFIF>
  <td><font face="wingdings">ç</font> <a href="NextN.cfm?start=#prevrec#">Previous #prev# records</a></td>
</CFIF>
<!--- Display next link --->
<CFIF end LT data.RecordCount>
  <CFIF start + disp * 2 GTE data.RecordCount>
    <CFSET next=data.RecordCount - start - disp + 1>
  <CFELSE>
    <CFSET next=disp>
  </CFIF>
  <td><a href="NextN.cfm?start=#Evaluate("start + disp")#">Next #next# records</a> <font face="wingdings">è</font></td>
</cfif>
</table>
</CFOUTPUT>
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #40  
Old 02-21-2008, 12:38 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - OnRequestEnd.cfm template

OnRequestEnd.cfm template

As all of you are probably aware, if you want to execute some code before a template executes, you place it in the Application.cfm. However, if there is some code that you want to display at the end of a templates execution (such as footers), you can do it with a template called OnRequestEnd.cfm. As the Application.cfm must have an upper-case A in order for it to execute correctly, OnRequestEnd.cfm must have an upper-case O, R, and E to execute.

To test it, you can create three files: Application.cfm, index.cfm, and OnRequestEnd.cfm

<!--- Application.cfm --->
Start!<br>

<!--- index.cfm --->
Index!<br>

<!--- OnRequestEnd.cfm --->
End!<br>

When you run it, you should see three lines of text in your browser:
Start!
Index!
End!

When you execute a template, Cold Fusion will search the directory for an Application.cfm template and if found, will execute it. If an Application.cfm template was not found, it will search up the directory tree until it finds one. If Cold Fusion finds an OnRequestEnd.cfm template in the same directory as the Application.cfm template, it will execute it once it's finished running the template the user executed. An OnRequestEnd.cfm template located in a different directory from the Application.cfm template will never be executed. Also, if an error occurred while processing your templates, the OnRequestEnd.cfm will not be executed.

For more information, see "Mapping Out an Application Framework" in Chapter 12 of the printer or online Cold Fusion documentation for "Developing Web Applications with ColdFusion".
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# .Net Tips & Tricks oxygen C# Programming 85 01-08-2009 12:25 AM
SAP Tips & Tricks leoraja8 Operating Systems 0 03-29-2008 12:11 AM
PHP Tips and Tricks Sabari PHP Programming 20 12-18-2007 05:26 AM
.NET tricks & Tips Karpagarajan VB.NET Programming 1 04-23-2007 08:17 AM
SEO Tips & Tricks spid4r Search Engine Optimization 0 03-08-2007 11:03 PM


All times are GMT -7. The time now is 03:39 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0