Michael Krumpe
asked on
Block Carriage-Return
I have an input box for freetext. I am already blocking the number of characters the user is allowed to type.
onkeypress="javascript:if( this.value .length >= 90){return false};"
How do I check for when the Enter Key (Carriage Return) is pressed and block it?
So that someone cannot enter
texttexttext
texttext
text
Because it must be inline, like
texttexttexttexttexttext
onkeypress="javascript:if(
How do I check for when the Enter Key (Carriage Return) is pressed and block it?
So that someone cannot enter
texttexttext
texttext
text
Because it must be inline, like
texttexttexttexttexttext
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Like this:
<input type="text" name="yourText" size="90" maxlength="90">
And if you have to use textarea, then check this:
<textarea name="yourArea" onKeyUp="if(this.value.mat ch(/[\n\r] /))this.va lue=this.v alue.repla ce(/[\n\r] /g,'');if( this.value .length>90 )this.valu e=this.val ue.substr( 0,90);"></ textarea>
<input type="text" name="yourText" size="90" maxlength="90">
And if you have to use textarea, then check this:
<textarea name="yourArea" onKeyUp="if(this.value.mat
for(i=0; i<str.length; i++){
if(str.indexOf("\n") > -1){
str= str.replace("\n", "");
}
}
That code is from memory, so you might want to play around which it. The ascii character for carriage return is 13, so I think you can do replace(chr(13), '') and achieve the same effect.