Javascript Shift+Enter (Firefox)

Posted by Stephen MCGinley on Stack Overflow See other posts from Stack Overflow or by Stephen MCGinley
Published on 2011-01-05T13:27:43Z Indexed on 2011/01/05 15:54 UTC
Read the original article Hit count: 139

Filed under:
|
|
|

Hi guys,

Had a look and found some things on this, but nothing seems to work as I'd like it.

Initially I had my solution working with internet explorer and chrome, but not firefox (which is unsatisfactory for me to not have working)

What I'm looking for is a simple text area, which sends data on enter key, but creates a new line on Shift+Enter. The following is what I have

function goReturn(e,str) {

  var e = (window.Event) ? e.which : e.keyCode;
  if (e.shiftKey && e=="13") {
    document.getElementById("wall").value = 
        document.getElementById("wall").value+"\n";
  } else if(e=="13"){
    // ...continue to send data
  }
}

This sends the data on enter, but also sends the data on shift and enter (which is the problem I have).

Thanks for any assistance

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about events