Forum Moderators: open

Message Too Old, No Replies

how do I replace returns with text

replace returns text

         

foto_hombre

1:35 am on Oct 20, 2007 (gmt 0)

10+ Year Member



I am not an experienced javascript coder so what I have probably can be done in a better way. However I need to take the text string from the text box on the form and replace the returns for text so I can then test the data. How do I replace the returns.

Example Code:

function checkCmnts()
{
var x = document.forms[0].Comments.value;
var filter1 = /^.+url=http+.+$/;
var filter2 = /^.+<+.+$/;
var filter3 = /^.+>+.+$/;
if (filter1.test(x)) document.forms[0].Comments.value = '';if (filter1.test(x)) exit;
if (filter2.test(x)) document.forms[0].Comments.value = '';
if (filter1.test(x)) exit;
if (filter3.test(x)) document.forms[0].Comments.value = '';if (filter1.test(x)) exit;
}

Fotiman

2:58 pm on Oct 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Maybe this will give you some ideas:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
<title></title>
</head>
<body>
<form action="#">
<div>
<textarea name="comments" id="comments" rows="9" cols="15"></textarea>
</div>
</form>
<script type="text/javascript">
window.onload = function() {
var c = document.getElementById('comments');
c.onchange = function() {
var s = this.value;
s = s.replace(/\r\n/g,"::");
alert(s);
};
};
</script>
</body>
</html>

foto_hombre

11:43 pm on Oct 24, 2007 (gmt 0)

10+ Year Member



Thanks. I've seen simular pieces of code, but couldn't make it work until now.