Forcing event.keyCode Character Into Input Box Value

R

Robert Nurse

Hi All,

I've got a form which I'm trying to submit automatically when the user
has entered 2 or more characters in a text imput box. Here's my set
up:

<SCRIPT language="JavaScript1.2">
function submitLetters(form, control)
{
var returnValue = true;

if (event.keyCode == 13)
returnValue = false;
else
{
if (CheckFilter(form) == true)
form.submit();
else
returnValue = false;
}

return returnValue;
}

function CheckFilter(form)
{
var returnValue = true;

if (form.nTypeFilter.value.length < 2)
returnValue = false;

return returnValue;
}

</SCRIPT>

<FORM name="displayByLastName" method="post" onSubmit="return
CheckFilter(this);">
<INPUT type="text" name="nTypeFilter" value="" onKeyPress="return
submitLetters(displayByLastName, this);">
</FORM>

I'm finding that nothing is getting into form.nTypeFilter.value until
submitLetters() returns true. How can I manually force the key
pressed into the form field's value from my onKeyPress handler? Also,
how do I get the actual event key character rather than just its
numerical value?
 
R

Robert Nurse

I figured out what to do! The value of the text box is available in
the onKeyUp event handler. Therefore, I can then check its length.
If it greater than two, submit the form. I'll have to watch out for
the backspace and delete keys though. But that's no problem.
 

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,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top