Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I disabled the Enter Key on my page. But i need to make enable the enter key only for Multiline textboxes. So that for Multiline textboxes i wrote the following javascript code. But when i press ENTER key in middle of the text (I mean, wrote a line of text and i want to break the line of text into two lines.), When i press ENTER it is adding a new line at the end. but i need in the middle(where i kept the cursor and pressed the enter key).

C#
function EnterEvent(e, ctl) {

            var keycode = (e.keyCode ? e.keyCode : e.which);
            if (keycode == 13 ) {
                ctl.value = ctl.value + '\n';
            }

        }
Posted
Comments
So, you need to find the cursor position first. Then at that position add the new line.
Try to search in Google to find the cursor position.

Where you written code to disable Enter key there put a checking to exclude textarea controls. No need to write above script in that case. The concept is allow enter for textarea only.
 
Share this answer
 
just check if active control is multiline textbox and enable it.
Just Simple
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900