I have a list with items.
When I click any of these items, I copy its id
-value into a form text
-field.
Everytime I click, it replaces the value, which is correct by default. But what I would like to add, is a way for the user to hold down a key on their keyboard, and when they then click, they just .append
whatever they just clicked into the same form field.
Here's my jQuery-code I'm using for the first/default scenario:
$(function(){
$('ul#filter-results li').click(function(){
var from = $(this).attr('id'); // get the list ID and
$('input#search').val(from+' ').keyup(); // insert into text-field then trigger the search and
$('input#search').focus(); // make sure the field is focused so the user can start typing immediately
});
});
Is there a way to implement some sort of keyboard key-listener?
Something like:
if (e.shiftKey){
.append('this text instead')
}
haven't tried out to see if shiftKey
is even any valid name here
There is a jQuery plugin for extended click.
You could try that or see how they have done it and implement it yourself.
ExtendedClick plugin
Hope this helps.
shiftKey
is of one of the properties of the event object and is valid to be used. try this:DEMO
This is what I ended up with:
I switched over to
altKey
becauseshiftKey
marked a lot of text when I clicked.Didn't do anything besides it doesn't look good...
Thanks for good suggestions...