DannyThunder
DannyThunder

Reputation: 1004

Cant set input value via JS after manually deleted the value (Chrome & FF)

Im creating a simple HTML form that lets you click on a text and set the value in an input field.

The problem is when I manually delete the value, I cant click and set a new value.

I created a JSFiddle: http://jsfiddle.net/s4faujvo/

    document.getElementById("pnr").setAttribute("value", this.textContent);

(Click on 2222 and 9999 to see it change, delete/blank the value manually, click on 222 or 999 again)

Am I doing something wrong here?

Upvotes: 0

Views: 81

Answers (1)

sergioFC
sergioFC

Reputation: 6016

Value is a property, not an attribute. To access, use: document.getElementById("pnr").value=this.textContent; .

Upvotes: 2

Related Questions