capturing from text area Shft+Enter, Control+Enter, Alt+Enter and browser issue.

H

HopfZ

I tried to detect modifier+enter key press in textarea in Firefox,
Opera and IE. The code is at the end. The result is
Firefox 1.5 : shift+enter, ctrl+enter, alt+enter all detected.
Opera 9 beta : shift+enter, ctrl+enter detected. alt+enter is
reserved for the browser.
Internet Explorer 6 : only shift+enter is detected.

Why e.ctrlKey and e.altKey are not being detected in IE? Is it by
design?

<html>
<head>
<script type="text/javascript">

function load(){
var ta = document.getElementById('ta');
ta.onkeypress = taKeyPress
ta.focus();
}
function taKeyPress(e){
var e = e || window.event;
var hasMod = e.shiftKey || e.ctrlKey || e.altKey;
var unicode = e.charCode || e.keyCode;
if(hasMod && unicode==13 /*hasMode and enter key*/){
alert('detected');
return false;// cancel key press.
}
}

</script>
</head>

<body onload="load()"><form>
<textarea id="ta">textarea</textarea>
</form></body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top