• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 138
  • Last Modified:

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

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'?
1 Solution
well i don't think the ondblclick event doesn't work within a selectbox. the ondblclick event is also not supported by all browsers
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.
Robert_FeldmanAuthor Commented:
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.
PAQed with points refunded (250)

Community Support Moderator

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now