function confirm_results(theform) {
var inputsX = document.getElementById(theform).getElementsByTagName('textarea');
for(var iX = 0, nX = inputsX.length - 1; iX < nX; iX++)
{
text += inputs[iX].innerHTML + ', ';
}
return text;
}
Can anyone tell me why this isn’t working? I’m trying to find all of the textarea’s inside a DIV that I pass the name through, and return the text. Some reason it just doesn’t do anything.
innerHTMLis not the right way to read a textarea’s value.Partly because any
<or&characters in it will be HTML-escaped, but mostly because the text node content inside anHTMLTextAreaElementnode is not indicative of the current value of the textarea.In fact the text node content is the original content of the textarea as seen in the HTML source. This is the same as the
defaultValueproperty. It does not get updated when you type in the textarea… except in IE which as usual gets it all wrong.You probably want to use
inputs[iX].valueinstead.The same goes for normal inputs, where
input.valuerepresents the current value butinput.getAttribute('value')is the same asinput.defaultValue, representing the original value put in thevalue="..."attribute in the HTML source. Again: except in IE due to more bugs.The same again applies to the
checkedandselectedproperties of checkboxes and select options: thecheckedandselectedattributes are the original values reflected in thedefaultCheckedanddefaultSelectedproperties.Also, with the
length-1you’re ignoring the last textarea in the list. Do you really mean to do that?