Changing onkeypress behavior for field element

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rick Measham

    Changing onkeypress behavior for field element

    I can't find this anywhere, so I hope it can be done:


    Here's what I can do so far:

    1. Certain fields have a class 'textfield' while others are
    'textfieldreq'.

    2. OnSubmit checks all elements and makes sure that those with 'req'
    have some value

    3. It then sets the border on empty required fields to red



    Now what I want to do is:

    4. alter the onkeypress for the field

    5. to restore the original class when someone enters something.



    Can this be done?

    Cheers!
    Rick
  • Lasse Reichstein Nielsen

    #2
    Re: Changing onkeypress behavior for field element

    Rick Measham <rickm@spam.com .au> writes:
    [color=blue]
    > 1. Certain fields have a class 'textfield' while others are
    > 'textfieldreq'.
    >
    > 2. OnSubmit checks all elements and makes sure that those with 'req'
    > have some value
    >
    > 3. It then sets the border on empty required fields to red[/color]
    [color=blue]
    > Now what I want to do is:
    >
    > 4. alter the onkeypress for the field[/color]

    Use onchange instead. It is probably what you want.
    [color=blue]
    > 5. to restore the original class when someone enters something.[/color]

    You didn't say that you changed the class, only the border style.

    Maybe something like this, in the code that recognizes empty fields:
    ---
    badElement.styl e.border = "2px solid red"; // or whatever you do
    badElement.onch ange = function() { this.style.bord er="";
    this.onchange=u ndefined; };
    ---
    If you insist on using "onkeypress ", change "onchange" to it

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...