How to respond to a double-click in a single-line drop list?

Posted on 2006-05-16
Last Modified: 2010-04-09
I want to run a script on a double-click in a <select> element that is SIZE='1', in other words one that looks like a single row drop list. I tried the following script, which works for SIZE greater than one, but if SIZE equals 1, it does not work.

      <SCRIPT LANGUAGE="JavaScript">
function takeAction(t)
return true
  <BODY><FORM><SELECT ONDBLCLICK="takeAction(this.options[this.selectedIndex])" SIZE='1'>
  <OPTION VALUE="opt1">opt1</OPTION>
  <OPTION VALUE="opt2">opt2</OPTION>
  <OPTION VALUE="opt3">opt3</OPTION>    

Is there a way to get it to work when SIZE='1'?
Question by:Robert_Feldman
    LVL 2

    Expert Comment

    well i don't think the ondblclick event doesn't work within a selectbox. the ondblclick event is also not supported by all browsers
    LVL 3

    Expert Comment

    He's right. The ondblclick event will only work on a select box with a size greater than 1. However, you can change your function to allow any other element to be double clicked and present an alert.

    function takeAction()
    var t = document.getElementById('selList');
    return true;

    Then add the id to your select box:

    <SELECT id="selList" SIZE='1'>

    Let's say you want to have the user double click on an image to run the function (as an example). You would use the following line:

    <img src="**" ondblclick="takeAction()" />

    I'm not sure how you plan on using this function. Using another element to launch the function may be more intuitive than double clicking on a drop-down box.

    Author Comment

    Thanks for the responses.

    I had wanted to use a double-click as a way to launch a form for adding more terms to the options list. I did not want to use a combo box, as I wanted to make adding terms more of a conscious effort than simply typing in the combo box's edit control, so that there would not get to be too many similar terms.

    What I have decided to do is use an option list item that sorts last -- "~Add New Item~" -- as a way to launch the other form. I have an onChange script that checks for this item. If it finds it, it launches the other form.

    Accepted Solution

    PAQed with points refunded (250)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now