Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using JavaScript to Simulate Enter

    Is it possible to use JavaScript to automatically press the Enter key when a textfield's value is changed? I'm guessing I would need to call the function using onChange="functionexample".

    After some research I found out the the map number for the Enter key is 13. I think this is the number JavaScript needs, I could be wrong.

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    why do you want to press enter?
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a form which has a section to choose a door number, each numeral is charged at £2.00. I have a script that calculates the amount of digits and that value is placed in a textfield.

    I also have another textfeild that shows the total value of the order, but the problem is that the total value won't update when the amount of digits changes. If you click in the field with the amount of digits and press enter it updates the total value.

    This was just a way round it I could think of.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    i ask because pressing enter usually triggers a form submit or onchange event.
    if that's the case, you can simply call form.submit() or input.onchange() - no reason to fake key presses...



    in other words, just do what enter does, don't do enter.

    post the code if you need a hand.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #5
    New Coder
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah I see.

    Just need to clarify where I should call this function?

    Should it be on:

    • The textfield with the amount of digits?
    • The textfeild with the total value?
    • The form itself?


    I was going to post the code, but it's too long. If you really need it to help me I will upload a text file.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •