1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

onchange works like onfocus. what to do?

Discussion in 'JavaScript' started by JEET, Feb 26, 2008.

  1. #1
    Hi,
    I got a form, and want something to happen when an "input" field is changed. I got the function done correctly working, but the change only happens when cursor leaves the field, or comes in it. (much like setfocus...)
    What to do?

    here's the code:

    <script type="text/javascript">
    function someS()
    {
    alert("some");
    }
    </script>
    <form action="some.php" method="post">
    type: <input type="text" name="s" id="s" onchange="someS();">
    <br>
    next: <input type="text" name="d" id="d" >

    </form>

    What I want is to execute the function as the user types...
    Thanks for help :)
     
    JEET, Feb 26, 2008 IP
  2. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #2
    Try onkeydown instead of onchange.
     
    rkquest, Feb 27, 2008 IP
    JEET likes this.
  3. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Use the same code and replace onchange with onkeydown
     
    selling vcc, Feb 27, 2008 IP
    JEET likes this.
  4. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #4
    ^ I beat you to it. :D
     
    rkquest, Feb 27, 2008 IP
  5. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #5
    Hi,
    Thanks both of you. Worked properly. Green rep added. Thanks :)
     
    JEET, Feb 27, 2008 IP
    selling vcc likes this.