March 18, 2006

innerHTML with ColdFusion

Filed under: ColdFusion, JavaScript — Phillip Holmes @ 3:50 pm

I hear lots of hype about AJAX these days but actually this technology is nothing new. While the use AJAX is a great tool, AJAX and the type of functionality it makes available has been around for many years. AJAX has simply standardized the model. Writing dynamic data to the DOM is really no big mystery and does not require anything more than old fashioned JavaScript and your favorite server side language. My advice about AJAX is to carefully consider what your application needs instead of running in and implementing it because it is the new buzzword or just because you can.

Here is an example of data that comes from a couple CF arrays and is then dynamically inserted into a JavaScript array. This data is then passed to a layer which utilizes the innerHTML tag to display it.

CODE:

  1. <cfscript>
  2.      arProdIDs = arraynew(1);
  3.      arProdIDs[1] = 240;
  4.      arProdIDs[2] = 256;
  5.      arProdIDs[3] = 257;
  6.      arPrice = arraynew(1);
  7.      arPrice[1] = 9.99;
  8.      arPrice[2] = 10.99;
  9.      arPrice[3] = 11.99;
  10.     intCount = arrayLen(arProdIDs);
  11.     intDiscount = 100;
  12. </cfscript>
  13. <script>
  14.      var products = new Array();
  15. </script>
  16. <cfscript>
  17.       for(i=1; i lte intCount;i=i+1) {
  18.            if(i EQ 1) {
  19.                 writeOutput('<script>');
  20.            }
  21.            writeOutput('products[#arProdIDs[i]#] = #arPrice[i]#;');
  22.            if(i EQ intCount) {
  23.                 writeOuput('</script>');
  24.            }
  25.       }
  26. </cfscript>
  27. <script>
  28.     function changeText(obj_input) {
  29.          intDiscount = #intDiscount#;
  30.          for(it in products) {
  31.               if(obj_input==it) {
  32.                    document.getElementById('dynaText').innerHTML =  intDiscount - products[it];
  33.                }
  34.           }
  35.      }
  36. </script>
  37. <div id="dynaText"></div>
  38. <form action="thispage.cfm" method="post" name="myform">
  39.      <cfloop from="1" to="#IntCount#" index="i">
  40.           <cfoutput>
  41.                <input type="radio" name="prodid" value="#arProdIDs[i]#" onclick="changeText(this.value)"/> #arProdIDs[i]#<br />
  42.           </cfoutput>
  43.      </cfloop>
  44.      <br />
  45.      <input type="submit"/>
  46. </form>

With ColdFusion 7, the export of dynamic data from ColdFusion to JavaScript has been made much easier with the addition of the toScript() function. I'll be posting more about toScript() and also about how to dynamically populate select menus without refreshing the page soon, so stay tuned!

March 10, 2006

Too Much Time On His Hands

Filed under: Fun Stuff! — Phillip Holmes @ 7:00 pm

This is a great article about what a man with too much time and a roll of stamps can accomplish!

Click Here Full Story

March 4, 2006

Randy Cunningham Gets 8 Years

Filed under: Politics — Phillip Holmes @ 12:00 am

SAN DIEGO, March 3 — After acknowledging that he had “made a very wrong turn,” former Representative Randy Cunningham was sentenced in federal court here on Friday to eight years and four months in prison for taking $2.4 million in bribes from military contractors in return for smoothing the way for government contracts.

The government, which called the misconduct unprecedented for its “depth, breadth and length,” said the sentence was the longest ever handed down for a member or former member of Congress in a federal corruption case.

In a halting, cracking voice before journalists, friends, political associates and others, Mr. Cunningham, 64, stood before the judge and largely read from a statement as he pleaded for leniency and, turning to prosecutors, apologized for his crime.

“I rationalized decisions I knew were wrong,” said Mr. Cunningham, a Naval pilot ace in the Vietnam War and “Top Gun” instructor who parlayed those experiences into a powerful political career. “Before there must be forgiveness, there must be redemption. No man has ever been more sorry.”

Judge Larry Alan Burns of Federal District Court said the former congressman’s conduct, which prosecutors said included keeping a “bribe menu” with the prices of influence, undermined faith in government and wasted tax dollars. In addition to some cash payments, Mr. Cunningham bargained for gifts like a sport utility vehicle, a Tiffany statue, Bijar rugs and candelabras.

Judge Burns said Mr. Cunningham, an eight-term Republican from Rancho Santa Fe who represented the northern suburbs of San Diego, could have retired to business long ago if he wanted to make copious money but instead engaged in bid rigging and badgering officials and other witnesses to help cover his tracks.

“You made a wrong turn and continued for three to five years,” Judge Burns said, referring to what prosecutors documented as the period of misconduct. “I wonder how far you would have gone.

“You undermined the opportunity and option for honest politicians to do a good job.”

The judge rejected Mr. Cunningham’s request to delay his arrival in prison so he could visit his 91-year-old mother, saying Mr. Cunningham had had months to say his goodbyes.

Judge Burns, in recognition of what Mr. Cunningham’s lawyers have described as his failing health, recommended sending him first to a prison medical center for evaluation. He also voiced admiration for Mr. Cunningham’s war heroism.

Mr. Cunningham’s lawyers had asked the judge for a six-year sentence, citing his military service and what they called health so failing that he may have seven years to live. Prosecutors urged the judge to abide by the 10-year sentence that Mr. Cunningham had agreed to after he pleaded guilty in November and resigned from Congress. Judge Burns noted that the sentence could be reduced by 15 months if Mr. Cunningham behaved well in prison.

Prosecutors said they might also seek a reduction if they are satisfied that he was cooperating with their investigation.

Mr. Cunningham was ordered to pay $1,804,031.50 in restitution for back taxes, penalties and interest owed to the government and was ordered to forfeit an additional $1,851,508, based on cash he received in his crimes.

The extent of corruption stunned his constituents and Republican colleagues on Capitol Hill and, along with the scandal centering on the lobbyist Jack Abramoff, sparked calls to change lobbying rules. The two investigations and others involving lawmakers and senior aides have emerged as major election themes.

Given Mr. Cunningham’s focus on funneling federal money to specific projects in exchange for lobbyists’ payoffs, his case put particular scrutiny on “earmarking,” using measures to direct money to favored projects.

Proposals are circulating in the House and Senate to require more disclosure of the projects and their sponsors and to open opportunities to strip the earmarks slipped into bills at the last minute.

In the weeks leading up to the sentencing, sharper details of Mr. Cunningham’s crimes emerged. In court papers, the government said he had behaved like an old ward boss, sketching out a “bribe menu” on a note card with the Congressional seal. One column offered $16 million in contracts in exchange for the title to a boat the contractor had bought for $140,000. The card further detailed how much more contract work could be bought for every additional $50,000 paid to Mr. Cunningham.

The papers document lavish travel on chartered jets paid by contractors with catered meals of lobster, wine and “other extravagances.” Bribers put him up at top-of-the-line resorts like the Royal Hawaiian on Oahu, Hawaii and in the Greenbriar Resort in West Virginia.

Mr. Cunningham, the government said, “bullied and hectored” officials standing in his way and tampered with witnesses to have them play down or distort his misdeeds.

The principal co-conspirator in the case, Mitchell Wade, a military contractor who is the founder and former president of MZM Inc. in Washington, pleaded guilty last week in federal court to several charges, including giving Mr. Cunningham $1 million in bribes.

Mr. Cunningham’s lawyers in court filings, including a psychiatric report, portrayed his life as disintegrating, saying ailments had left him with perhaps seven years to live.

The psychiatric report, by Dr. Saul J. Faerstein of Beverly Hills, Calif., said Mr. Cunningham suffered depression and suicidal thoughts, in addition to a history of prostate cancer and other ailments.

Searching for an explanation for Mr. Cunningham’s conduct, Dr. Faerstein said: “Society needs heroes and wants them to be superheroes. The normal sense of mortality is suppressed in order to fulfill this role.”

After the sentencing, two marshals approached Mr. Cunningham and escorted him without handcuffs from the courtroom, one of them guiding him by the waist, patting him on the back and whispering in his ear. Mr. Cunningham will spend perhaps a week or so in a jail across the street before moving to prison, said an assistant United States attorney, Phillip L. B. Halpern, who helped prosecute the case.

On March 23, the government plans to auction some of the antiques that Mr. Cunningham forfeited after pleading guilty, including French armoires, candlesticks, nightstands and a glass buffet.

March 3, 2006

try, catch, finally within cfscript

Filed under: ColdFusion, Java — Phillip Holmes @ 11:40 pm

Whenever I look at my blog's statistics, I always see cf'ers searching for try catch examples within cfscript. So far, the ColdFusion portion of my blog has featured 'one off' code for odd situations and such. I completely forgot that most people that are looking for examples like try catch instead. What I've decided to do here is feature a little more than my stats log has requested by listing a try catch a couple languages so you can see how CF stands up to a full blown programming languages like Java or C#.

-----

A Java or C# try catch would go something like this:

CODE:

  1. try {
  2.      // the code you want to try to run
  3.      } catch (SomeException e) {
  4.     // code to run when their is an error
  5. }
  6. finally {
  7.   // This is code that runs regardless of the error.
  8. }

-----

This is the ColdFusion equivalent:

CODE:

  1. try {
  2.      foo = 1;
  3.      } catch(any excpt) {
  4.      foo = 2;
  5. }

-----

CODE:

  1. function finally() {
  2.      foo = 3;
  3.      return foo;
  4. }
  5. try {
  6.      foo = 1;
  7.      } catch(any excpt) {
  8.      foo = 2;
  9. }
  10. foo = finally();

-----

So, there it is! I hope that helps those folks out there looking for that example! Thanks for visiting and please come back often as I update frequently.

The Holmes Blog