Joel
Joel

Reputation: 460

Printing a value to input tag with innerHTML

I'm having a problem with printing a text string to a input tag.

The javascript:

imgDiv.innerHTML += "<input type='text' value=" + text[i].firstChild.data + ">";

The generated html looks like this:

<input type="text" fjäril="" svart="" och="" orange="" value="En">

Does anyone have a suggestion on what is causing this problem?

Upvotes: 0

Views: 467

Answers (1)

potashin
potashin

Reputation: 44581

value attribute's value should be also wrapped in quotes (like you did with type attribute):

imgDiv.innerHTML += '<input type="text" value="' + text[i].firstChild.data + '">';

Upvotes: 2

Related Questions