Results 1 to 5 of 5
  1. #1

    no BR with javascript

    I have a textarea in HTML:
    Code:
    <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:
    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;
    		}
    	}
    }

  2. #2
    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...

  3. #3
    The "onKeyUp" is good and working well, My problem is this live "RegExp("[\n]", "g")".
    I'm not sure "\n" is good.
    ?

  4. #4
    Join Date
    Mar 2004
    Posts
    1,303
    here is another way on how to detect press "Entery" key

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

  5. #5
    Just add \r to replace: 'replace(/[\n\r]/g,"")'
    works fine, just tested.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •