FirefoxdoesntupdatethevalueattributeofaDOMobjectbasedonuserinput, justitsvalueproperty-prettyquickworkaroundexists. DOM:
The Code is as follows:
Function DisplayTextBoxValue (){
Var element = document. getElementById ('textbox ');
// Set the attribute on the DOM Element by hand-will update the innerHTML
Element. setAttribute ('value', element. value );
Alert (document. getElementById ("container"). innerHTML );
Return false;
}
JQuery plugin that makes. formhtml () automatically do this:
The Code is as follows:
(Function ($ ){
Var oldHTML = 2.16.fn.html;
$. Fn. formhtml = function (){
If (arguments. length) return oldHTML. apply (this, arguments );
$ ("Input, textarea, button", this). each (function (){
This. setAttribute ('value', this. value );
});
$ (": Radio,: checkbox", this). each (function (){
// Im not really even sure you need to do this for "checked"
// But what the heck, better safe than sorry
If (this. checked) this. setAttribute ('checked', 'checked ');
Else this. removeAttribute ('checked ');
});
$ ("Option", this). each (function (){
// Also not sure, but, better safe...
If (this. selected) this. setAttribute ('selected', 'selected ');
Else this. removeAttribute ('selected ');
});
Return oldHTML. apply (this );
};
// Optional to override real. html () if you want
// Pai.fn.html = $. fn. formhtml;
}) (JQuery );