Combining onKey. event's within an input tag.

C

CES

All,

I'm trying to create a simple counter that reports the number of remaining
characters within a specific element. I was wondering is their a way of
combining onKey Events so that you don't have to write a line like the
following:

onFocus="fCharacterRemain('1')" onKeyDown="fCharacterRemain('1')"
onKeyUp="fCharacterRemain('1')"

I know I can shorten the function name but I was wondering if their was a
way of monitoring any activity(KeyEvent) within a form or element alowing me
to remove the onKeyDown, onKeyUp events.

CES

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="JavaScript">

function fCharacterRemain(sender){
// var fName = fGetFormName(sender);
// FYI - I have multipule forms on the page
var fName = "Form_1";
var cValue = document.forms[fName].elements['id_' + sender].value;
var cCount = cValue.length;
var maxChr = document.forms[fName].elements['id_' +
sender].getAttribute("maxlength");
var rChr = maxChr - cCount;

document.getElementById('id_temp').innerHTML = rChr;

}

</script>
</head>

<body onload="">

<p id="id_temp">

</p>

<form name="Form_1" action="test0.htm" method="get" >

<input id="id_1" name="Text_6" type="text" maxlength="50"
onFocus="fCharacterRemain('1')" onKeyDown="fCharacterRemain('1')"
onKeyUp="fCharacterRemain('1')" /><br>

</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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top