Thursday, April 21, 2011

Adding a Javascript Function to a Blogger Blogpost

I had a lot of trouble getting the income calculator java code to work in the previous post then i discovered a poorly written post that clued me in. If you copy paste java script code into the edit html portion of the blogger editor it wont work. Thats because when the post is published blogger converts carriage returns into <br > messing up the java script.

If you want javascript to work you have to put the entire javascript code block on one line. Thats an impossible task to do manually for complex code blocks. So write and test them elsewhere and then once your satisfied it works use this tool. It will strip the new lines placing the entire block of text on one line. Copy and Paste the single line version of your code into the blog editing pane in the blogger editor and you are good to go.

No comments: