Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6776315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:00:47+00:00 2026-05-26T16:00:47+00:00

Would it be possible for me to dynamically add an event handler to a

  • 0

Would it be possible for me to dynamically add an event handler to a form field. I need to do this, because in the scope of the work I am doing – the form field to which this is added is chosen dynamically.

So, I want to know if something like this would work:

document.forms['Form1'].elements['chosen_field'].onkeydown = some_function();

EDIT:

Another sub-question here. I want to pass on the event to some_function(), but do not want to return anything back. Is there a way I can do that? Essentially I am using some_function() to update some JS variable – and for that I need to find out what key was pressed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:00:48+00:00Added an answer on May 26, 2026 at 4:00 pm

    When you assign event handlers like this

     document.forms['Form1'].elements['chosen_field'].onkeydown = some_function();
    

    You are saying assign whatever some_function returns to this keydown event.

    You need to drop the () from it so you assign a reference to the function.

     document.forms['Form1'].elements['chosen_field'].onkeydown = some_function;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would it be possible to add a new operator to the String class that
I was wondering if it's possible to dynamically add subdomains that point to dynamic
How would I dynamically add methods to my module through the C-API? I have
I would like to dynamically add properties to a ExpandoObject at runtime. So for
Possible Duplicate: How do you disable browser Autocomplete on web form field / input
Is it possible to dynamically add UNION clauses in LINQ? I have a list
I have a class which the programmer can use to dynamically add new properties.
I was wondering if it would be possible to retrieve the complete list of
Any other tweaks for making emacs as vim-like as possible would be appreciated as
Hey, I'm just wondering if it would be possible to convert videos to mp3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.