Web Hosting Talk







View Full Version : no BR with javascript


noamway
12-25-2006, 07:21 PM
I have a textarea in HTML:
<textarea type="text" name="tranT" onKeyUp="noBR(this.form.tranT);"></textarea>

and I try to don't let the user click on the ENTER key, but my code don't work, someone can find the problem.

I wrote this code:
function noBR(x)
{
var reg = new RegExp("[\n]", "g")

if (x)
{
if (reg.test(x.value))
{
alert("Please don't use the 'ENTER' key, Use <br> instead!");
x.value = x.value.replace(/[\n]/g,"")
x.focus();
return false;
}
}
}

azizny
12-25-2006, 11:12 PM
Try using onChange instead of onKeyUp.

Peace,

noamway
12-25-2006, 11:20 PM
The "onKeyUp" is good and working well, My problem is this live "RegExp("[\n]", "g")".
I'm not sure "\n" is good.
?

orbitz
12-25-2006, 11:21 PM
here is another way on how to detect press "Entery" key

http://jennifermadden.com/javascript/stringEnterKeyDetector.html

PilgrimX182
12-26-2006, 04:15 AM
Just add \r to replace: 'replace(/[\n\r]/g,"")'
works fine, just tested.