Reputation: 365
How do I make a select option selectable by double click?
E.g. I double click "Option Text #3" and the value of option three shall be written into a hidden input field with id="selectedOption".
Upvotes: 0
Views: 8482
Reputation: 1239
i tried the first answer that returns whole option html.
$('select option').dblclick(function() {
$('#selectedOption').val($(this).html());
});
use this one instead.
Upvotes: 0
Reputation: 154
Try this code:
$('select option').dblclick(function() {
$('#selectedOption').val($("#select option:selected").val());
});
Upvotes: 1
Reputation: 74738
You can use dblclick
this way:
$('select option').dblclick(function() {
$('#selectedOption').val(this.outerHTML);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select size="4">
<option>Option # 1</option>
<option>Option # 2</option>
<option>Option # 3</option>
<option>Option # 4</option>
</select>
<input type='text' id='selectedOption' value=''>
Upvotes: 6