TextBox Question??

Discussion in 'JavaScript' started by locbtran, Mar 30, 2010.

  1. #1
    I would like to type something into my textbox and then press ENTER, it will execute a function.

    I tried onFocus, onChange and onBlur but it doesn't do what I want it to.

    Here's an example I use for onChange.

    Application: <input type="text" onchange="execProg(0);">
    Code (markup):
    Any comments or suggestions is greatly
     
    locbtran, Mar 30, 2010 IP
  2. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    use the onkeydown or onkeyup events. There you can call a function which will check what key was pressed with and then execute the code you want.
    
    if(event.keyCode == 13) {
        // put you code here... keyCode for Enter is 13 ;)
    }
    
    Code (markup):
     
    Nyu, Mar 30, 2010 IP
  3. nimonogi

    nimonogi Active Member

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    80
    #3
    If you want to be executed on enter, then i think you should change it to:

    
    Application: <input type="text" onsubmit="execProg(0);">
    <input type=submit value="Submit">
    
    Code (markup):
     
    nimonogi, Mar 30, 2010 IP