Onkeypress event is not working correctly.... ?

I

Ivan

<html>

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



function findvdn()

{

var vdnedit=document.getElementById("vdnfield").value;
//document.getElementById("vdnfield").focus();
if (8==vdnedit)
{
alert ("hi");
}
}
</script>

<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<input type="text" id="vdnfield" onkeypress= "findvdn();"
onchange="findvdn();"name="T1" size="20">

</body>

</html>


This is a very simple example just to demonstrate but when i type 8
doesnt appear straight away but when i type the next digit .. how can
i do it so that the alert appears while i type??Thanks
 
B

Bart Van der Donck

Ivan said:
<html>
<head>
<script type="text/javascript">
function findvdn()
{
var vdnedit=document.getElementById("vdnfield").value;
if (8==vdnedit)

if (vdnedit == '8')
{
alert ("hi");}
}
</script>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<input type="text" id="vdnfield"   onkeypress= "findvdn();"
onchange="findvdn();"name="T1" size="20">
</body>
</html>

This is a very simple example just to demonstrate but when i type 8
doesnt appear straight away but when i type the next digit .. how can
i do it so that the alert appears while i type??

I think you are looking for 'onkeyup' in stead of 'onkeypress'.

Cheers,
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top