Forum Moderators: open

Message Too Old, No Replies

doubleclick multi-select box to copy to textbox?

         

partha

11:50 pm on Apr 13, 2005 (gmt 0)

10+ Year Member



Is it possible make javascript for this:

I have a <select multiple> with a few <option>s in it. I want it so when I double click one of the <option>s, it appends the value of that <option> to the <input type="text"> that last had focus.

It's so that I can have a list of commonly used keywords and easily throw a few of them into a keywords input.

Bernard Marx

12:11 am on Apr 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No onclicks on options, I'm afraid, but you could have a button beside the select.
When the button is clicked, the options are looped, and the values of the selected options are collected up and dumped into your textbox.

partha

12:21 am on Apr 14, 2005 (gmt 0)

10+ Year Member



oh man that's complicated

Bernard Marx

8:49 am on Apr 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not really :)

<html><head><title>TEST</title>
<script type="text/javascript">
function getChoices(form)
{
var values, options, option, k=0;
values = new Array();
options = form.choices.options;
while(option=options[k++])
if(option.selected)
values[values.length] = option.value;
form.output.value = values.join(' ');
}
</script>
</head>
<body>

<form>
<select name="choices" multiple>
<option value="1">one
<option value="2">two
<option value="3">three
<option value="4">four
<option value="5">five
</select>
<input type="button" value="select" onclick="getChoices(this.form)">
<input name="output" type="textbox">
</form>

</body>
</html>

CgiBin

5:42 pm on Apr 14, 2005 (gmt 0)

10+ Year Member



Does it HAVE to be a multi-select form element?

If not you could fake it by creating a styled div with the options as child divs, and assign a ondblclick handler to each.

<div class="fakeSelect">
<div class="fakeOption" ondblclick="someFn('some value')">Option Label</div>
.
.
</div>