PDA

View Full Version : keyboard shortcut


dnguyen
09-11-2002, 08:00 PM
I'm not looking for keyboard shortcuts and my users want to use keyboard to have the current date show up on the form instead of typing it. The problem with this, is that the field my users want to insert a current date is a comment field. And they want to have control when current date is to be inserted. Instead of it been there everytime. I got this code from another webForum but it only works in IE. I would this to work in Netscape and I'm not very familiar with javascript.

Any help would be appreciated.

Thanks,


<HTML>
<HEAD>
<TITLE>Hot Key Demo</TITLE>

<SCRIPT LANGUAGE=javascript>
<!--
var isCtrlKeyPressed = false;

function hotkey(eventname)
{

if(eventname.keyCode == 17)
{
isCtrlKeyPressed = true;
}
if(eventname.keyCode == 68 && isCtrlKeyPressed)
{
adddate();
}

}
function adddate()
{
document.test.comment.value = "<CFOUTPUT>#DATEFORMAT(NOW(), "MMMM D, YYYY")#: </CFOUTPUT>";
document.test.comment.focus();
}
//-->
</SCRIPT>

</HEAD>

<BODY onkeydown='hotkey(event)'>

<form name="test">
<textarea name="comment" cols="50" rows="4"></textarea>
</form>


Use Ctrl + D to insert date

</font>
</BODY>
</HTML>

x_goose_x
09-11-2002, 09:44 PM
<HTML>
<HEAD>
<TITLE>Hot Key Demo</TITLE>

<script language="JavaScript"><!--
//from http://www.irt.org
var date = new Date();
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;

thedate = day + "/" + month + "/" + year;

var isCtrlKeyPressed = false;

function hotkey(eventname)
{

if(eventname.keyCode == 17)
{
isCtrlKeyPressed = true;
}else{
isCtrlKeyPressed = false;
}
if(eventname.keyCode == 68 && isCtrlKeyPressed)
{
document.test.comment.value += thedate;
document.test.comment.focus();
}
return true;
}
//-->
</SCRIPT>

</HEAD>

<BODY onkeydown='hotkey(event)' ;>

<form name="test">
<textarea name="comment" cols="50" rows="4"></textarea>
</form>


Use Ctrl + D to insert date
</BODY>
</HTML>

dnguyen
09-12-2002, 04:12 PM
Thank you for your reply, but the code doesn't work. The code that I've attached works in IE but not in Netscape. The keyboard key in Netscape for "D" is 100 and "CTRL" is 0. I have changed the key (see below) but it still does not work in Netscape. So I think that maybe the function (isCtrlKeyPressed) is not recognized by Netscape.

<HTML>
<HEAD>
<TITLE>Hot Key Demo</TITLE>

<SCRIPT LANGUAGE=javascript>
<!--
var isCtrlKeyPressed = false;

function hotkey(eventname)
{

if(eventname.keyCode == 100)
{
isCtrlKeyPressed = true;
}
if(eventname.keyCode == 0 && isCtrlKeyPressed)
{
adddate();
}

}
function adddate()
{
document.test.comment.value = "<CFOUTPUT>#DATEFORMAT(NOW(), "MMMM D, YYYY")#: </CFOUTPUT>";
document.test.comment.focus();
}
//-->
</SCRIPT>

</HEAD>

<BODY onkeydown='hotkey(event)'>

<form name="test">
<textarea name="comment" cols="50" rows="4"></textarea>
</form>


Use Ctrl + D to insert date

</font>
</BODY>
</HTML>