...

View Full Version : Event.KEYPRESS



angiras
01-14-2004, 02:34 PM
I got this script

function kH(e) {
var pK = document.all? window.event.keyCode:e.which;
return pK != 13;
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);

because I have a problem with a sign out button

now no enter button works, is it possible to desable enter keypress only for one button ?

thank you

A1ien51
01-14-2004, 03:35 PM
I am sure there is a better solution, but it works:



<script>
Allow=true;
function handleKeyPress(evt) {
var nbr, chr;
if (window.Event) nbr = evt.which;
else nbr = event.keyCode;
if(nbr==13 && !Allow){
return false;
}
}
function AllowSubmit(X){
Allow=X;
}

document.onkeydown= handleKeyPress
</script>


<form name="FormName">
<input type="button" name="ElementName" onclick="alert('eric1')" onfocus="AllowSubmit(false)" onblur="AllowSubmit(true)" value="No Enter">
<input type="button" name="ASDF" onclick="alert('eric2')" value="Enter">
</form>


Eric

angiras
01-14-2004, 03:45 PM
but I don't want any ebent I want just that enter doesn't submit the form on a special button

let say <button id="Logout" />

thanks for helping

A1ien51
01-14-2004, 04:05 PM
????

angiras
01-14-2004, 04:12 PM
yes of course but I don't understand .... how can I get one button without enter, and other yes

with a kind of code

<input type="button" id="Login" value="Sign In" />


<input type="button" id="Logout" onclick="noEnter('this.Id')" value="Sign out" />


??

Login will work with enter
and logout not

thank you

A1ien51
01-14-2004, 04:30 PM
You can not click enter on this button
<input type="button" name="ElementName" onclick="alert('eric1')" onfocus="AllowSubmit(false)" onblur="AllowSubmit(true)" value="No Enter">

You can click enter on this button
<input type="button" name="ASDF" onclick="alert('eric2')" value="Enter">

angiras
01-14-2004, 04:41 PM
<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Enter | no Enter</title>
<script>
Allow=true;
function handleKeyPress(evt) {
var nbr, chr;
if (window.Event) nbr = evt.which;
else nbr = event.keyCode;
if(nbr==13 && !Allow){
return false;
}
}
function AllowSubmit(X){
Allow=X;
}
document.onkeydown= handleKeyPress
</script>
</head>
<body>
<form id="MainForm">
<input type="button" id="ElementName" onclick="alert('eric1')" onfocus="AllowSubmit(false)" onblur="AllowSubmit(true)" value="No Enter" />
<input type="button" id="ASDF" onclick="alert('eric2')" value="Enter" />
</form>
</body>
</html>

noramlly if I press enter I should get eric2 ....

any way enter doesn't work it is the main thing

thank you

angiras
01-15-2004, 11:03 AM
it doesn't work at all in this way I need the keypress for a script in dropdownlist , and with this code nothing works

it must be possible to unallow keypress.enter only for one control ?

in my case it is only for the logout button ...

thank you for helping

Garadon
01-15-2004, 11:21 AM
<input type="button" id="ASDF" onclick="alert('eric2')" value="Enter" onkeypress="return false;" onsubmit="alert();">


note it was the wrong button I did it to I think lol, but only thing u should need to do is put 'onkeypress="return false;" ' in the rigth button.

angiras
01-15-2004, 11:31 AM
<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Enter | no Enter</title>
</head>
<body>
<form id="MainForm">
<input type="button" id="ASDF" onkeypress="alert('Enter')" value="Enter" />
<input type="button" id="ElementName" onclick="alert('No Enter')" onkeypress="return false;" value="No Enter" />
</form>
</body>
</html>

ok keypress doesn't work ..., is it right iin that way ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum