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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:02:15+00:00 2026-05-30T09:02:15+00:00

My question is different than just "how do I get the selected option from

  • 0

My question is different than just "how do I get the selected option from a select box".

In select box, no option element is ‘selected’ prior to right-clicking on it.
On right-clicking an option, I want to get the value of that option element.

Therefore, option:selected won’t work.

<select name='mySel' id='mySel' multiple>
  <option value='val1'>myOption1</option>
  <option value='val2'>myOption2</option>
</select>

I have bound rightclick event to the context menu:

// bind right click event to context menu
(function( $ ) {
  $.fn.rightClick = function(method) {
  $(this).bind('contextmenu rightclick', function(e){
    e.preventDefault();
    method();
    return false;
    })

  };
    })( jQuery );

The event handler code below will only work if an option is selected prior to right clicking:

$('#mySel').rightClick(function(e){
  alert($('#mySel option:selected').text());
    });

Without using option:selected, how do I get the value of right-clicked option?

  • 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-30T09:02:17+00:00Added an answer on May 30, 2026 at 9:02 am

    The target property of the event parameter will refer to the element which triggered the event, in your case the option element that was right-clicked:

    $('#txBase').rightClick(function(e){
      alert(e.target.value); // val1 or val2
    });
    

    DEMO

    A few notes about your code:

    • no need to return false and to e.preventDefault, both statement have the same result so just use one or the other

    • you might wanna check if method is not undefined and is a function before calling it, otherwise it will break

    • when you call method, pass the parameter e to it otherwise you won’t be able to use inside your callback

    Here’s the modified code:

    $(this).bind('contextmenu rightclick', function(e) {
        e.preventDefault();
    
        if (method && $.isFunction(method)) {
            method(e); // pass the event parameter to your callback
        }
    
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From another stackoverflow question, it seems that Android handles large bitmaps differently than other
[Please note that this is a different question from the already answered How to
my question is a bit different from the other ones.. i got an xsl-code
This question can be little different than you expect. I am wondering how would
As a bit of a different question than my usual ones, I thought it
I was just answering a question about different approaches for picking the partition in
This is a little different than the questions that have already been asked on
this is a different question concerning: add a connection to database not working, asp.net
I asked a question about different testing frameworks yesterday. This question can be found
I'll rewrite a different question of mine, because the problem case somewhat changed: If

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.