I’m trying to learn JS, so forgive me if you code makes the world explode.
Anyway, I am trying to make a tagging system interface similar to SOs. Where the user types in words and SO separates them on the comma (or on spacebar but I don’t want that).
I am using jQuery to access the DOM (because it is so much easier), and I know there are various plugins that could do this and feed the homeless, but as I said I want to learn.
Here’s what I have so far:
<input type="textbox" name="somebox" id"someid">
$(document).ready(function() {
var startPos = 0;
$("#someid").keyup(function() {
var inputText = $(this).val();
var commaPosition = inputText.indexOf(",", startPos);
var foundWords = [];
alert('Hello'); // even this doesn't work... why???
if (commaSearch !== '-1') {
// take the word:
foundWords.push(inputText.slice(startPos,commaPosition));
startPos = commaPosition + 1;
}
});
});
It can also be found here. Nothing seems to work, not even the alert. Any help would be grateful.
Is this what you want?
DEMO