I have the following code:
$("#tag-add-button").click(function () {
var text = $("#tagadd").val();
var tagcounter=0;
$("#set-tags").append("<%= render 'tag' %>");
$("#tag"tagcounter).val(text);
$("#tagadd").val("");
tagcounter=tagcounter+1;
});
Clearly its wrong, but here is what I'm trying to accomplish:
Someone clicks the tag-add-button, the text from tagadd is stored in the "text" var.
The variable tagcounter is set to 0
An input is rendered (within the set-tags div) containing an id such as "tag0", "tag1" etc.
The input ("tag0" etc.) then receives the value from the "text" var.
The original input box "tagadd" is then replaced with nothing ("").
Lastly the tagcounter variable increases by 1.
How can I make this work?
.data. Best to avoid global state.$("#set-tags").append("<%= render 'tag' %>");doesn't make any real sense?