The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

adding tags using String.replace()

When trying to emulate php's nl2br() function in javascript, I ran into something quite disturbing.

Code:

cms.t.value = cms.t.value.replace(/\n/gi, '<br />\n');

Using this piece of code, I was really surprised that the newlines weren't preceded by <br />, but by <br>. I really don't understand why that would happen. Why can't I decide my own replacement string? .

I've tried it with both Mozilla (Firebird) and MSIE6, and both browsers behaved the same, that's what surprised me most..

It should become a semi-graphical interface for posting blogs. Click on the gray div and it turns into a textarea. Click outside the textarea and it should become a div, with the textarea's value parsed. Newlines in the textarea should automatically convert to <br />s, to do that, put a few newlines in the textarea, click outside of it and than click back on it. Newlines are then replaced by <br> (mozilla) or <BR> (IE).

Your example worked fine for me too, by the way. But I haven't yet been able to find the difference..

Feel free to comment on it by the way, this is my first "Learning javascript" try .

Oh, and by the way: IE is acting really strange when updating the content, hiding everything and showing each element on the page only when hovering over it. Now this is not a huge problem, because I use Mozilla primarily and it's going to be for private use, but still. Anybody has a clue how that happens, and/or how to prevent it from happening?

Oh, and also: I'm assigning event handlers for onclick and onblur events, executing functions from the cms class. In those functions, I can't use this.functionName() but I have to use cms.functionName(). This means the object can only be constructed correctly when it's named "cms". Any workaround for that? (another reference to the same object that I can use, or something?)

Hmm, I think this sounds kinda vague. But if you look at the updateTextbox and updateDiv methods I hope you understand wht I mean..

I'll check your project out, but I don't think I'll use it, the whole reason I started this thing is because Midas' functionality was too limited for me. But it might help me out if I become stuck again in the future .