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 8414437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:10:15+00:00 2026-06-10T01:10:15+00:00

In the traditional way to add event listener: function getComboA(sel) { var value =

  • 0

In the traditional way to add event listener:

function getComboA(sel) {
    var value = sel.options[sel.selectedIndex].value;  
}

<select id="comboA" onchange="getComboA(this)">
<option value="">Select combo</option>
<option value="Value1">Text1</option>
<option value="Value2">Text2</option>
<option value="Value3">Text3</option>
</select>

But I wanted to adapt to the addEventListener way:

productLineSelect.addEventListener('change',getSelection(this),false);

function getSelection(sel){
    var value = sel.options[sel.selectedIndex].value;
    alert(value);
}

It doesn’t work because I can’t pass any parameter in getSelection() as the second parameter in addEventListener method? As far as I know I can only use the function name without parenthesises.

Any idea?

BTW, please look at my previous question about console.log doesn’t work in Safari 6.0 Developer Inspector, I can’t write any output in the console, which is frustrating.

  • 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-06-10T01:10:16+00:00Added an answer on June 10, 2026 at 1:10 am

    No need to pass anything in. The function used for addEventListener will automatically have this bound to the current element. Simply use this in your function:

    productLineSelect.addEventListener('change', getSelection, false);
    
    function getSelection() {
        var value = this.options[this.selectedIndex].value;
        alert(value);
    }
    

    Here’s the fiddle: http://jsfiddle.net/dJ4Wm/


    If you want to pass arbitrary data to the function, wrap it in your own anonymous function call:

    productLineSelect.addEventListener('change', function() {
        foo('bar');
    }, false);
    
    function foo(message) {
        alert(message);
    }
    

    Here’s the fiddle: http://jsfiddle.net/t4Gun/


    If you want to set the value of this manually, you can use the call method to call the function:

    var self = this;
    productLineSelect.addEventListener('change', function() {
        getSelection.call(self);
        // This'll set the `this` value inside of `getSelection` to `self`
    }, false);
    
    function getSelection() {
        var value = this.options[this.selectedIndex].value;
        alert(value);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was used to the traditional way of doing database searching with the following
I noticed that I can't combine --traditional options with the other one letter other
I got many [Required] fields in my model. And, in traditional MVC way, I
I'm used to the traditional way of using FTP - where I simply upload
I've been using, up until now, the traditional way to benchmark concurrent methods, which
Anyone got an idea why this doesnt work? Im tyring to add the listener
Traditional task of iterating trough key set of std::map led me to another mess
In traditional ASP.NET (Web Forms), the UpdatePanel control lets you do a partial refresh
A traditional C++ class (just some random declarations) might resemble the following: class Foo
I have a traditional ASP.NET GridView. Inside of it I have a Template Field

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.