html input displays different text to value that it posts html input displays different text to value that it posts codeigniter codeigniter

html input displays different text to value that it posts


This is a case of attributes vs. properties.

What you are seeing in the inspector is the value attribute, which does not update when you programmatically update a field's value property.

Pay no attention to what the DOM inspector says; it'll only show the value as it was when the page loaded (unless you explicitly change the field's value attribute rather than, as jQuery's val() does, its value property.)

Further reading: http://jquery-howto.blogspot.co.uk/2011/06/html-difference-between-attribute-and.html

Some attributes are closely tied to their property counterparts. That is to say, updating the property also updates the attribute. This is the case, for example, with the class attribute and its className property counterpart. value, however, is different; updating the property does not update the attribute (but, just to confuse things further, updating the attribute does update the property!)


val() is changing the value property, not attribute. The value attribute is initialized at the loading of the page. Once you change text field the value property and attribute have differnet values.

But you can use plain JS for changing the value attribute also.

Try:

var cubes=123.2;document.getElementById('qty').setAttribute('value',cubes);var test=$("#qty").val();alert(test);

DEMO