Naeem wrote:
Hi,
Quote:
var myForm = document.getElementsByTagName("form")[0];
document.forms[0] // simpler :)
Quote:
myForm.removeChild(myForm.stateId);
Quote:
Function displays the correct value in alert. but on line 3
myForm.removeChild(myForm.stateId);
it gives following error. I am using Firefox.
>
Error: uncaught exception: [Exception... "Node was not found" code:
"8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)" location:
"http://localhost:8080/APP/premiseCatalog.do Line: 245"]
Firefox tells you that the node has not been found; as Evertjan said,
the problem lies with your HTML, the parent of your stateId element
probably being some other element than the form.
---
<head>
<script type="text/javascript">
var foo=(function(){
var cached_select=createElement(
"<select name='stateId'><option value='hello'>Hello<\/select>"
);
var cached_input=createElement(
"<input type='text' name='stateId'>"
);
function createElement(str) {
var div=document.createElement("div");
div.innerHTML=str;
return div.firstChild;
}
return function(form){
var el, type=form.stateId.nodeName.toLowerCase();
form.removeChild(form.stateId);
switch (type) {
case "input" : el=cached_select; break;
case "select" : el=cached_input; break;
}
form.insertBefore(el,form.firstChild);
}
})();
</script>
</head>
<body>
<form action="#">
<input type="text" name="stateId">
<input type="button" value="Toggle" onclick="foo(this.form)">
</form>
</body>
---