473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Shift+Enter doing different function than just Enter from textarea

eboyjr14
I need to make it so that when you're entering data into a textarea, and press shift+enter it creates a new line where the caret is at, then when you press enter it sends a message. This is like most chat applications.

What's wrong with this code:

Expand|Select|Wrap|Line Numbers
  1. <textarea id="msginput" onkeypress="return onEnter(event,this.value,this);" onkeydown="chkShift(event);"></textarea>
and...

Expand|Select|Wrap|Line Numbers
  1. function chkShift( evt )
  2.     {
  3.     var key = null;
  4.     if( evt.which )
  5.         {
  6.         key = evt.which;
  7.         }
  8.     else if( evt.keyCode )
  9.         {
  10.         key = evt.keyCode;
  11.         }
  12.     if ( key == 16 )
  13.         {
  14.         document.getElementById('shifter').value = "true"
  15.         }
  16.     else
  17.         {
  18.         document.getElementById('shifter').value = "false";
  19.         }
  20.     }
  21. function onEnter( evt, msg, obj )
  22.     {
  23.     var keyCode = null;
  24.     if( evt.which )
  25.         {
  26.         keyCode = evt.which;
  27.         }
  28.     else if( evt.keyCode )
  29.         {
  30.         keyCode = evt.keyCode;
  31.         }
  32.     if( 13 == keyCode )
  33.         {
  34.         if (document.getElementById('shifter').value == "true")
  35.             {
  36.             obj.value += "\n";
  37.             document.getElementById('shifter').value = "false";
  38.             }
  39.         else
  40.             {
  41.             if (msg != "" && document.getElementById('titletext').innerHTML != "" )
  42.                 {
  43.                 sndMessage(msg, document.getElementById('titletext').innerHTML);
  44.                 obj.value = "";
  45.                 }
  46.             }
  47.             document.getElementById('shifter').value = "false";
  48.         return false;
  49.         }
  50.     return true;
  51.     }
Jun 1 '07 #1
1 5759
acoder
16,027 Expert Mod 8TB
Use event.shiftKey to detect the shift key.
Jun 1 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rob | last post by:
I am trying to build in some basic security into a database via user forms. How do I stop a user from entering MS Access via windows explorer by pressing Shift+Return and thus force them to enter...
2
by: ansi_c | last post by:
hello, I just developed an .adp application linked to SQL Server 7, I compiled it disabling also all the shortcuts from the tools->startup menu and obtained an .ade project. My problem is that...
4
by: Vazz | last post by:
I am trying to capture the key combination "Control + Shift + Enter" in a KeyDown event. I am able capture "Control + Enter" using (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control). How do I...
4
by: carmela_wong | last post by:
How can I protect my database so that the end user needs to open it using Shift+Enter? Thanks
1
by: ray | last post by:
Hi, Now, I have a datagrid with data input. The data type is nvarchar. While I press "SHIFT+ENTER", it moves to a new row for the same data row. Can I prevent it from happening? Thanks a lot,...
2
by: pemigh | last post by:
Client's fingers have been well trained on another application to wrap lines by hitting shift-enter, and wants the same in Access application. Changing "enter key behavior" for controls is not...
2
by: Sunfire | last post by:
I was wondering if there was a way to hit enter to insert blank lines while in the designer? I tried this but all it seems to want to do is insert code that really shouldn't be there. For example,...
9
by: dale5804 | last post by:
poss a silly question, but basically i have a database where its properties mean when it is opened (enter / double click) the actual database, and options (file/edit/...etc) are hidden and only the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.