Forcing event.keyCode Character Into Input Box Value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert Nurse

    #1

    Forcing event.keyCode Character Into Input Box Value

    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="JavaS cript1.2">
    function submitLetters(f orm, control)
    {
    var returnValue = true;

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

    return returnValue;
    }

    function CheckFilter(for m)
    {
    var returnValue = true;

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

    return returnValue;
    }

    </SCRIPT>

    <FORM name="displayBy LastName" method="post" onSubmit="retur n
    CheckFilter(thi s);">
    <INPUT type="text" name="nTypeFilt er" value="" onKeyPress="ret urn
    submitLetters(d isplayByLastNam e, this);">
    </FORM>

    I'm finding that nothing is getting into form.nTypeFilte r.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?
  • Robert Nurse

    #2
    Re: Forcing event.keyCode Character Into Input Box Value

    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.



    rnurse@cudbytec h.net (Robert Nurse) wrote in message news:<a967f5b9. 0406241221.54b1 632@posting.goo gle.com>...[color=blue]
    > 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="JavaS cript1.2">
    > function submitLetters(f orm, control)
    > {
    > var returnValue = true;
    >
    > if (event.keyCode == 13)
    > returnValue = false;
    > else
    > {
    > if (CheckFilter(fo rm) == true)
    > form.submit();
    > else
    > returnValue = false;
    > }
    >
    > return returnValue;
    > }
    >
    > function CheckFilter(for m)
    > {
    > var returnValue = true;
    >
    > if (form.nTypeFilt er.value.length < 2)
    > returnValue = false;
    >
    > return returnValue;
    > }
    >
    > </SCRIPT>
    >
    > <FORM name="displayBy LastName" method="post" onSubmit="retur n
    > CheckFilter(thi s);">
    > <INPUT type="text" name="nTypeFilt er" value="" onKeyPress="ret urn
    > submitLetters(d isplayByLastNam e, this);">
    > </FORM>
    >
    > I'm finding that nothing is getting into form.nTypeFilte r.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?[/color]

    Comment

    Working...