Question

When I have HTML input fields and a change them by direct input they should actually change there value attribute. But when I try to get the whole HTML record it just shows the old value attributes. Somehow this is clear to me, couse the HTML is not overwritten, but I need the HTML containing the changed input values. How can I approach it?

Example:

$('input').addEvent('blur', function(){
    alert($('adiv').get('html'));
});

<div id="adiv">Enter something in input box and press tab<div>....<input id="input" type="text" value="1">the mootools will grep the old value of 1 again....</div></div>

http://jsfiddle.net/hJtzc/1/

alerts allways:

> Enter something in input box and press tab<div>....<input id="input"
> type="text" value="1">the mootools will grep the old value of 1
> again....</div>

but what I need to get is:

> Enter something in input box and press tab<div>....<input id="input"
> type="text" value="[VALUE FROM USER]">the mootools will grep the old
> value of 1 again....</div>
Was it helpful?

Solution

Attribute value in HTML sets initial, default value of the element, DOM property value contains the actual, real value of the element . To change the default value of input element change defaultValue property:

$('input').addEvent('blur', function(){
    this.defaultValue = this.value;
    alert($('adiv').get('html'));
});

This is normal behavior that is not related to mootools framework

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top