SkyeBoniwell
SkyeBoniwell

Reputation: 7112

retrieving the text value from 2 textareas

I am using the following jquery/backbone.js code snippet to get the text values from 2 textareas on the page and write them to two labels in another area on the page.

this.input.each(function () {
    val = val + ($(this).val());
});

toDoList.create({ title: val });

The code successfully gets the data from the 2 textareas, but when it displays that data in the label, it is displaying it as one label.

So if the two values of the textareas are 'foo' and 'bar', it just shows:

<label>foobar</label>

I assume this is because I am just getting the textarea values in the loop and not separating them.

Is there a way to rewrite this so I can output something like:

<label>foo</label>
<label>bar</label>

thanks

Upvotes: 1

Views: 42

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337626

If you need separate labels, create them within the loop. The concatenation of the two values becomes redundant.

this.input.each(function () {
    toDoList.create({ title: $(this).val() });
});

Upvotes: 2

Related Questions