Results 1 to 5 of 5
Thread: no BR with javascript
-
12-25-2006, 07:21 PM #1Junior Guru Wannabe
- Join Date
- Jun 2005
- Posts
- 77
no BR with javascript
I have a textarea in HTML:
Code:<textarea type="text" name="tranT" onKeyUp="noBR(this.form.tranT);"></textarea>
I wrote this code:
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; } } }
-
12-25-2006, 11:12 PM #2Web Hosting Master
- Join Date
- Mar 2004
- Location
- USA
- Posts
- 4,345
Try using onChange instead of onKeyUp.
Peace,Testing 1.. Testing 1..2.. Testing 1..2..3...
-
12-25-2006, 11:20 PM #3Junior Guru Wannabe
- Join Date
- Jun 2005
- Posts
- 77
The "onKeyUp" is good and working well, My problem is this live "RegExp("[\n]", "g")".
I'm not sure "\n" is good.
?
-
12-25-2006, 11:21 PM #4Web Hosting Master
- Join Date
- Mar 2004
- Posts
- 1,303
here is another way on how to detect press "Entery" key
http://jennifermadden.com/javascript...yDetector.html
-
12-26-2006, 04:15 AM #5Newbie
- Join Date
- May 2005
- Posts
- 8
Just add \r to replace: 'replace(/[\n\r]/g,"")'
works fine, just tested.