• 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.

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


Is there a way to get it to work when SIZE='1'?
0
Robert_Feldman
Asked:
Robert_Feldman
1 Solution
 
topscoderCommented:
well i don't think the ondblclick event doesn't work within a selectbox. the ondblclick event is also not supported by all browsers
0
 
jeaton32Commented:
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');
alert(t.options[t.selectedIndex].value);
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.
0
 
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.
0
 
CetusMODCommented:
PAQed with points refunded (250)

CetusMOD
Community Support Moderator
0

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