1

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.

3
  • what is the value of $('#description textarea') ? Commented Nov 16, 2009 at 10:47
  • I just updated the question :) Commented Nov 16, 2009 at 10:50
  • I reimplemented the code and your basic idea is sound. But as mentioned below $('#description textarea') does not match your textarea. Basically your selector is wrong so use one of the answers below and you should be golden! Commented Nov 16, 2009 at 11:02

4 Answers 4

1

Use html() for textareas...

var txt = $("#description");
txt.html(txt.html().replace(/%%%VERSION%%%/g, '');
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

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);

1 Comment

As i told @Darin Dimitrov this dosen't seems to have any effects on the VERSION tags.. ( I know about the above text ). thx
0

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.

4 Comments

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
Do you have more than one element id'd with #description?
No, nothing.. :-( Could it be the replace(/%%%VERSION%%%/g That need to be changed ? The current text looks like this: /static/%%%VERSION%%%/
Your regex is fine. I recreated it as you specified in the question and it works just fine in firefox 3.5.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.