Posting javascript in blogger

I once tried to post some javascript inside the post itself and found out that it was not working.

Well seems like if you want to embed <script> tags inside the post, and you have “Convert line breaks” set to true (by default), you cannot add script tags, as Blogger would add <br /> instead of your line breaks.

So you need to write down your script in one single line.

Which is what this post actually does. Use it to your heart’s content :)

Post your javascript here

Remove New Lines Remove Multiple spaces Replace <, > to &lt; and &gt; resp.

Enjoy :)

BTW, the javascript for the above is embedded in this post itself. And here’s the code, use it on the above textarea ;-):

<script type="text/javascript">

function toggleCheckbox(docid) {
var rs = document.getElementById(docid);
rs.checked = !rs.checked;
function removeNewLines() {
var rnl = document.getElementById("removeNewLines");
var rs = document.getElementById("removeSpace");
var rlt = document.getElementById("replaceLt");
var c = document.getElementById('content').value;
var r = rl(c, rnl.checked, rs.checked, rlt.checked);
document.getElementById('result').value = r; 

function rl(str, rnl, rs, rlt) {
if (rnl) {
 str =  str.replace(/[\n\r\t]/g,' ');
if (rs) {
 str = str.replace(/ [ ]*/g,' ');
if (rlt) {
 str = str.replace(/</g,'&lt;').replace(/>/g, '&gt;');
return str;

Published 23 March 2009
comments powered by Disqus