how would I make it so that this code only replaces EACH = as I type them into the textarea with "\=" and NOT MORE THAN ONE \ ? new_text = new_text.replace("=","\\=");
it returns \\\=\\=\= instead of \=\=\=
Full code:
<script type="text/JavaScript">
function html2entities(sometext){
var re=/[(<>"'&]/g
arguments[i].value=sometext.replace(re, function(m){return replacechar(m)})
alert(arguments[i].value);
}
function replacechar(match){
if (match=="<")
return "<"
else if (match==">")
return ">"
else if (match=="\"")
return """
else if (match=="'")
return "'"
else if (match=="&")
return "&"
}
//html2entities(document.forms.myform.textarea.value); //replace "<", ">", "&" and quotes in a form field with corresponding HTML entity instead
function generate(strValue)
{
var newValue;
newValue = replaceString(strValue, "<br>", "<br/>");
newValue = replaceString(strValue, /\=/g, "\\=");
document.forms[0].textarea.value = newValue;
}
function replaceString(inputStr,SearchPattern,ReplaceWith)
{
return inputStr.replaceAll(SearchPattern,ReplaceWith);
}
</script>
<form name="form1" method="post" action="">
<textarea name="textarea" onkeyUp="javascript:generate(document.forms.myform.textarea.value);"></textarea><br>
<input type="button" name="Generate" value="Generate">
</form>