Thursday, 15 August 2013

javascript - HTML input value attribute - same input, (apparently) different results -



javascript - HTML input value attribute - same input, (apparently) different results -

how value attribute work html input tag after edit via inputbox?

example:

<input type="text" name="test" id="test" value="hello world" />

this show input box text "hello world". if edit inputing new string rendered textbox (not via raw code), , seek value using js this

alert(document.getelementbyid('test').value)

i'll, correctly, new value. if inspect element through chrome developer tools (or firebug or prefer), i'll see same "hello world" string in beginning..

which of 2 right one? js value or chrome inspector?

here's example fiddle , here's screenshot

i came while trying find solution problem: classic shop situation, have table x inputs tag , user can input quantity of x items. need check if 1 or more values have changed since previous value of each input: if comparing between old , new val returns valuehas changed, need update order. otherwise there's no need save/update.

i thought utilize attr. "value" store "old" value of input, not best choice..

can explain behaviour? it's "refresh" problem or there else behind?

both right, show different things.

the dom value property gives current value.

the html value attribute gives default value (the same dom defaultvalue property).

the chrome dom inspector shows attribute values in html view. have @ property view see property values.

javascript html input

No comments:

Post a Comment