Reputation: 453
I want to display a list of items when user hits control-enter button.
I know so far that I can use jquery trigger event to open a list. But I dont know how can I display that list in the textarea so that user can select an item from the list and set it to the textarea.
$("textarea").trigger(some event here to open the list);
Upvotes: 0
Views: 1546
Reputation: 6793
If I understand you correctly, try the following:
SEE the FIDDLE
HTML:
<div id="myDiv">
<a>Enter</a><br />
<div>
<textarea>
</textarea>
</div>
</div>
<div id="select">
<select id="abc1">
<option value="volvo">Option1</option>
<option value="saab">Option2</option>
<option value="mercedes">Option3</option>
<option value="audi">Option4</option>
</select>
</div>
JS:
$('#myDiv a').click(function(){
$('#select select').appendTo('#myDiv');
$('#select').css('display','block');
var text1 = $('#abc1 option:selected').val();
$('#myDiv textarea').html(text1);
$("#abc1").change(function () {
var str = "";
$("#abc1 option:selected").each(function () {
str += $(this).text() + " ";
});
$("#myDiv textarea").html(str);
})
.change();
});
Upvotes: 1
Reputation: 1
var text = $('textarea#msg').val();
or
var text = $("#msg").val();
are correct. May be you can try
var text = $("#msg").text();.
also if you are trying to get value of textarea on click event of button then try getting it in
$(document).ready().
Upvotes: 0