Forum Moderators: open
function changeTextBox2TextArea(elementId)
{
var _el = document.getElementById(elementId);
var _parent = _el.parentNode;
// we remove the element from the DOM (optional as seen below...)
_parent.removeChild( _el );
// property is read-only so we replace the element
if ( _el.type == 'text' ) {
// IE doesn't like too much playing with DOM, so we use the innerHTML method.
// Using innerHTML, replace all current elements inside _parent with the new
// elements specified in the string.
_parent.innerHTML = '<textarea id="' + _el.id + '">' +
_el.value + '</textarea>';
} else {
_parent.innerHTML = '<input type="text" id="' +
_el.id + '" value="' + _el.value + '" />'; }
_el = null; // remove any reference to the old element
}
<input type="button" value="Change Text Box"
onclick="changeTextBox2TextArea('test');" />
<div>
<input type="text" id="test" />
</div>
As RonPK said it's probably 'cos you missed the SCRIPT tags. IE7 is probably smart enough to realise this.
I always wondered why if you get an error 'expected )' or similar, why doesn't it just add it? It obviously knows where it's supposed to go or it would be complaining!