views:

90

answers:

4

Hey

I'm trying to Replace a %%%VERSION%%% text, the text is coming from an tinyMCE editor.

looks like this.

$("#description textarea").val($("#description textarea").val().replace(/%%%VERSION%%%/g, STAT_VERSION_INFO));

The value of the textearea is:

<textarea rows="20" cols="117" name="description" id="description">Some code version info: %%%VERSION%%%</textarea>

But i can't make it replace anything.

Any idéas how to fix it, or maybe other solutions.

A: 

Just replace $("#description textarea") with $("#description") or $("textarea#description"). The first selector will look for a textarea inside a DOM element with id=description, while in your case it is the textarea that has id=description.

Hope this makes sense.

Darin Dimitrov
I tried your solution, but nothing seems to fix it :S If i replace another text instead of the %%%VERSION%%%, it works fine... but not with the version tags :S
william
Do you have more than one element id'd with #description?
MDCore
No, nothing.. :-( Could it be the replace(/%%%VERSION%%%/gThat need to be changed ?The current text looks like this: /static/%%%VERSION%%%/
william
Your regex is fine. I recreated it as you specified in the question and it works just fine in firefox 3.5.
MDCore
+1  A: 

To select: $("#description textarea") => $("textarea#description") or just $("#description")

To do the changes:

var textarea = $("textarea#description");
var text = textarea.html().replace(/%%%VERSION%%%/g, '');
textarea.html(text);
AndreasKnudsen
As i told @Darin Dimitrov this dosen't seems to have any effects on the VERSION tags.. ( I know about the above text ). thx
william
+1  A: 

Change .val() to .html() and it works: Example here http://jsbin.com/uwidu/

Eivind
+1  A: 

Use html() for textareas...

var txt = $("#description");
txt.html(txt.html().replace(/%%%VERSION%%%/g, '');
Josh Stodola