A stupid JavaScript mistake...

Have you ever spent an hour on something that was so simple that upon solving it you wonder how you possess enough brain power to have ever learned to write a simple statement? Well I did and I'm writing this entry for anyone else who has ever felt like they should be immediately de-rezzed! Yeah - I just went TRON on you...

So here's the situation. I've got a cfloop that is dynamically building form controls. On some of the form controls I want to dynamically change the background color of the control if a user changes the value of said control. Sounds easy right, mix a little CF and jQuery and that should go down as easy as Captain and Coke - only I forgot the ice.

So if you need to pass an input control to a JavaScript function and then dynamically take action based on the name of the control, don't forget to handle the small things - like say concatenating the proper characters into your input control's name so that you can properly reference them in your JavaScript code.

Here's the caller...

view plain print about
1<cfselect name="status#ContainerID#" query="qryContainerStatusSelector" value="ContainerStatusCode" display="ShortDesc" selected="#StatusCode#" style="background-color:yellow;" onChange="manageEditedControlState(this)"/>

Now we want the JavaScript function manageEditedControlState to handle changing the background color for us...

view plain print about
1manageEditedControlState = function(editedControl){    
2        var controlID = editedControl.name;
3        $('#' + controlID).css("background-color", "orange");
4    }

So what's laughable here is that I forgot to add the little pound + var name $('#' + controlID) and then I shouted at the screen for a good number of minutes. Then I did what I always seem to do, I sent an e-mail to Ray Camden but solved it before he had time to reply or publicly humiliate me on his blog. Don't be fooled people, he is a roving TMZ reporter (covering stupid RIA developers and noobs) and if you see him and you're having an off day then you need to run. Just kidding Ray, good job on releasing Picard.

Comments
Russ S.'s Gravatar I admit I have done the same thing many times before, although I never would have had the guts to ask Ray Camden why my jQuery script isn't working.

On a side note: why not use jQuery events instead?
$('#selectBox').onChange(function(){
$(this).css("background-color", "orange");
});
A lot easier to read and understand if you ask me!
# Posted By Russ S. | 4/7/10 4:35 PM
Russ S.'s Gravatar Speaking of mistakes, I think I should've written "change" instead of "onChange". Here's the jQuery docs on that: http://api.jquery.com/change/
# Posted By Russ S. | 4/7/10 4:39 PM
Andy Sandefer's Gravatar @Russ - thanks for the tip! I'm still learning jQuery and I've only been at it sporadically for a few months now but I love it and use it on projects whenever I can. I just recently bought the jQuery Cookbook so I'm planning on getting to know jQuery a lot better over the next few months. I'll definitely reach out to you if I get stuck (now aren't you glad that opened your mouth and helped - LOL :0)
# Posted By Andy Sandefer | 4/7/10 4:49 PM
Lizeth's Gravatar Great post. Visit the Rapidshare Search engine( http://www.rapidsharemix.com/trends/sk/12-04-2010.... ) page today and have fun using this site.
# Posted By Lizeth | 4/13/10 12:16 PM
mbt shoes's Gravatar I agree with everything else you just said. Maybe we are not so far apart in our doctrinal views…Peace and Grace to you
# Posted By mbt shoes | 5/14/10 4:13 AM
mbt shoes's Gravatar Awesome article as usual, thanks for posting such helpful content on a regular basis.
# Posted By mbt shoes | 5/14/10 8:13 AM
# Posted By coach handbags | 5/17/10 5:23 AM
Rapidshare Search Engine's Gravatar Good article. Please visit my website Rapidshare Search Engine http://www.family-resource.com/210510/mapa1.html
# Posted By Rapidshare Search Engine | 5/20/10 10:05 PM
# Posted By chanel bags | 5/28/10 1:01 AM
# Posted By coach handbags | 5/30/10 11:04 PM
ed hardy clothing's Gravatar http://www.ed-hardy.cc swimsuit bikini
http://www.ed-hardy.cc women swimsuit
http://www.ed-hardy.cc swimsuit girls
# Posted By ed hardy clothing | 5/31/10 5:13 AM
# Posted By coach outlet | 6/8/10 10:15 PM
# Posted By coach outlet | 6/8/10 10:16 PM
# Posted By coach outlet | 6/8/10 10:18 PM
# Posted By coach outlet | 6/9/10 3:08 AM
coach bags outlet's Gravatar I really like your article, I support your point of view
# Posted By coach bags outlet | 6/17/10 10:20 PM
# Posted By coach outlet | 7/2/10 12:21 AM
batterie's Gravatar I never would have had the guts to ask Ray Camden why my jQuery script isn't working.
# Posted By batterie | 7/20/10 8:51 AM
labatterie's Gravatar I admit I have done the same thing many times before
# Posted By labatterie | 7/20/10 8:52 AM
r4 ds's Gravatar I'll definitely reach out to you if I get stuck (now aren't you glad that opened your mouth and helped ……
# Posted By r4 ds | 7/20/10 8:53 AM
handychina's Gravatar !!!!!!!!!!!!!!http://www.efox-shop.com/ !!!!!!!!!!!!
` ?—? ? ??`_?
????????????? ohne Vertrag,
????????????? Handy ohne Simlock?
??????????????Sciphones i68,
?????????????Touchscreen Handys und
????????????? Handy Zubeh?
????????????? re von Elektronik-
?——???????——?Grosshandel in
?????????? http://www.efox-shop.com/.
?????????? ??????
????????????????
# Posted By handychina | 7/22/10 1:04 AM
handychina's Gravatar thanks for your sharing.
And I have something for you.it is nice?
ohne Vertrag, Handy ohne Simlock?Sciphones i68,
Touchscreen Handys und Handy Zubeh?re von Elektronik-
Grosshandel in http://www.efox-shop.com/.
<a href=“http://www.efox-shop.com/”>China Handya</a>
# Posted By handychina | 7/22/10 1:05 AM
NFLjerseys's Gravatar Newest style of [url=http://www.nfljerseys-shopping.com/]NFL jerseys[/url] has arrived, get the details at nfljerseys-shopping.com.. Purchase [url=http://www.nfljerseys-shopping.com/]cheap jerseys[/url] here since [url=http://www.nfljerseys-shopping.com/]football jerseys[/url] are having promotion now.
# Posted By NFLjerseys | 7/27/10 12:13 AM
# Posted By ed hardy | 7/27/10 4:03 AM
# Posted By mbt shoes | 7/27/10 5:02 AM
handyking's Gravatar eFox-shop.com puts quality at the top of business plan. Our Quality Control team carries out various testing processes to ensure only quality products are sold on the web. No counterfeits or reimbursed items would appear on our selling lists.
http://www.efox-shop.com/
# Posted By handyking | 7/28/10 9:58 PM
Apad's Gravatar Hipad www.efox-shop.com/product_info.php/products_id/1040
Epad www.efox-shop.com/mobileshop/index.php/cPath/37
Opad www.efox-shop.com/mobileshop/index.php/cPath/37

Tablet PC www.efox-shop.com
Tablet Laptop www.efox-shop.com
Touchscreen Tablet Laptop www.efox-shop.com/product_info.php/products_id/1040
Q7 android 2.1
Apad www.efox-shop.com/product_info.php/info/p784_CEM004-Apad-iRobot-7-Zoll-Android-1-5-Tablet-PC-MID-Ipad-Style.html" target="_blank">www.efox-shop.com/product_info.php/info/p784_CEM00...
# Posted By Apad | 8/1/10 11:40 PM
NFL Jerseys's Gravatar Your idea coincides with mine.and I think it's better.
http://www.nfljerseyspaypal.com cheap nfl jerseys
http://www.nfljerseysgo.com NFL Shop
http://www.nfljerseysgo.com NFL Jerseys
http://www.eightshop.com polo shirts
# Posted By NFL Jerseys | 8/24/10 12:03 AM
oakley sunglasses's Gravatar Once again great post. You seem to have a good understanding of these themes.When I entering your blog,I felt this . Come on and keep writting your blog will be more attractive. To Your Success!
http://www.onesunglasses.com oakley sunglasses
http://www.onesunglasses.com ray ban sunglasses
http://www.onesunglasses.com gucci sunglasses
# Posted By oakley sunglasses | 8/24/10 12:05 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.5.007. Contact Blog Owner