Showing posts with label ColdFusion. Show all posts
Showing posts with label ColdFusion. Show all posts

Wednesday, December 2, 2009

Javascript and ColdFusion

JavaScript changed my url variables.

I recently debugged a piece of old code that was doing some weirdness. In the code a JavaScript function was run after a combo box was changed. The function reloaded the same page with a few url variables. One of the url variables was changing when it reloaded. I found out JavaScript was calculating the numerical value and returning a different number, ( example: 027 became 17 ).

The original code looked something like this:
<code>
function recalcWeek()
{
var year=document.forms[0].slctFiscalYear.options[document.forms[0].slctFiscalYear.selectedIndex].value;
location.href="somePage.cfm?div_no="+<cfoutput>#url.div_no#</cfoutput>+"&event_id="+<cfoutput>"#url.Event_ID#"</cfoutput>+"&fiscal_year="+year;
}
</code>

The corrected code to fix the issue looked like this:
<code>
function recalcWeek()
{
var year=document.forms[0].slctFiscalYear.options[document.forms[0].slctFiscalYear.selectedIndex].value;
location.href="somePage.cfm?div_no=<cfoutput>#url.div_no#</cfoutput>&event_id=<cfoutput>#url.Event_ID#</cfoutput>&fiscal_year="+year;
}
</code>


The mistake was using the double quotes and the + to try and concatenate the values. ColdFusion will render the variable in the ## before JavaScript uses them so there is no need to concatenate. If you would do a view source on the page, or use Firebug, you would see the function after ColdFusion renders the variables and then the mistake becomes more obvious.

Thursday, July 17, 2008

TODO in CFEclipse

Can't say how much I like the TODO comment feature in CFEclipse. See this article for more info. All you have to do is add "TODO" in a comment and it will appear in your tasks list.


inside scripts .... // TODO: Do this later

No excuse for forgetting stuff now .... unless you forget to use TODO!!

Sunday, July 13, 2008

StructCopy vs Duplicate

Sean Corfield wrote an excellent blog explaining the differences between structCopy(), duplicate(), and normal assignments of structs. Check it out here, http://corfield.org/blog/index.cfm/do/blog.entry/entry/Explaining_StructCopy. This has been confusing for some developers. Bravo Sean!