|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How To: Change characters in a textarea? Using Javascript
Hello,
I'm fairly new to java so please bare with me! So, at the moment I have a form with a textarea which is generating XHTML for me, this all works fine. Now, I would like to know how to change characters in the textarea when the "generate" button is clicked. For example! Say I had a <br> tag... I would like it to loop through the document that has been loaded into the textarea and change all instances to <br /> I would really appreciate it, if someone could push me in the right direction or perhaps provide some code that I can use to achieve this as it's been really bugging me! Thanks! |
|
#2
|
||||
|
||||
|
Example: It doesn't work with multiples, but it gives you an idea on how to do it.
Code:
<script type="text/JavaScript">
function generate(strValue)
{
var newValue;
newValue = replaceString(strValue, "<br>", "<br/>");
document.forms[0].textarea.value = newValue;
}
function replaceString(inputStr,SearchPattern,ReplaceWith)
{
return inputStr.replace(SearchPattern,ReplaceWith);
}
</script>
<form name="form1" method="post" action="">
<textarea name="textarea"></textarea><br>
<input type="button" name="Generate" value="Generate" onClick="javascript:generate(textarea.value);">
</form>
|
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > How To: Change characters in a textarea? Using Javascript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|