Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To detect a <code>@</code>, you'd do something like :</p> <pre><code>$("#recommendTextArea").keyup(function (e) { if (e.which===50) { alert('you typed @'); } }); </code></pre> <p>and <code>this.value</code> get's you whatever is typed into the textarea, and you'll need a regex to get what's between <code>@</code> and the first following space, or something similar depending on how you intend to do this ?</p> <p>To get a name, you can do something like this :</p> <pre><code>var _name = false; $("#recommendTextArea").keyup(function (e) { if (_name) { $('#name').text('name : ' + this.value.substring( this.value.lastIndexOf('@') ) ) } if (e.which === 50) { _name = true; } if (e.which === 32) { _name = false; } }); </code></pre> <p><a href="http://jsfiddle.net/F5Hmj/3/" rel="nofollow"><strong>FIDDLE</strong></a></p> <p>This is just a quick demo, building something that always works and accounts for every possible outcome will be a lot more work than this.</p> <p><strong>EDIT:</strong></p> <blockquote> <p>Most importantly what I need is the index of the'@' that the user just entered.</p> </blockquote> <p>that would be <code>this.value.lastIndexOf('@')</code></p> <p><strong>EDIT AGAIN:</strong></p> <p>To get the names typed in the textarea regardless of cursor position, number of names etc. you'll have to use a regex, here's a quick example that gets all and any names typed in, as long as they start with a @, and ends with a blank space :</p> <pre><code>$("#recommendTextArea").keyup(function (e) { var names = this.value.match(/@(.*?)\s/g); $('#name').html('names typed : &lt;br/&gt;&lt;br/&gt;' + names.join('&lt;br/&gt;')); }); </code></pre> <p><strong>FIDDLE</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload