Click to See Complete Forum and Search --> : Guestbook pre-processing


geoman123321
03-24-2003, 10:32 AM
I am creating a guestbook and I use javascript to pre-process the information fields to make sure they are filled correctly. How do I take out all of the carriage returns from a comment field so that when I save it to a file it doesn't enter down a bunch if someone types:

Test



Test'


Test.

????
thankyou

khalidali63
03-24-2003, 12:13 PM
Which language are you using to save the data in DB.

In C/C++ and Java, we use '\n' for carriage return and its a character value which can be detected.

Cheers

Khalid

Nedals
03-24-2003, 12:21 PM
If you do exactly as asked you will end up with this

TestTest'Test.

which I don't think you want. Here's some javascript that will return this

Test Test' Test.

<html><head><title>Untitled</title>
<script type="text/javascript">
<!--
function view() {
text = document.forms[0].elements[0].value; alert(text);
text = text.replace(/[\n\r]/g,' '); alert(text); // replace the returns with a space
text = text.replace(/( )/g,''); alert(text); // remove double spaces
}
//-->
</script>
</head>

<body bgcolor="#ffffff">
<form>
<textarea cols=30 rows=5></textarea>
<input type=button value="view text" onClick="view()">
</form>
</body>
</html>