Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » myForm.appendChild(domElement) doesn't work
icon9.gif  myForm.appendChild(domElement) doesn't work [message #662216] Tue, 29 March 2011 18:26 Go to next message
g-dawg  is currently offline g-dawg Friend
Messages: 2
Registered: March 2011
Junior Member
I have the following javascript in my app
function addDataField(frmObj, typeStr, nameStr, valueStr){
  alert(document.getElementsByTagName("form").length + " forms exist");
  var fld = document.createElement("input");
  fld.type = typeStr;
  fld.name = nameStr;
  fld.value = valueStr;
  alert("input field created");  // <-----  This displays fine
  document.getElementsByTagName("form")[0].appendChild(fld);
  alert(document.getElementsByName(nameStr)[0].name + "\n" + 
      document.getElementsByName(nameStr)[0].value); // <----- This never displays in Eclipse debugger
}


This functionality works wonderfully in IE and FF - but not in the Eclipse debugger tab. My big issue is that I'm trying to debug the PHP code that follows this functionality and I NEED this to function in order for the PHP to get the proper POST data. This could be a configuration issue (probably is) but I haven't been able to figure out why all of my other javascript is working but this one function/method is not.

[Updated on: Tue, 29 March 2011 19:19]

Report message to a moderator

Re: myForm.appendChild(domElement) doesn't work [message #662281 is a reply to message #662216] Wed, 30 March 2011 05:01 Go to previous message
Toshihiro Izumi is currently offline Toshihiro IzumiFriend
Messages: 360
Registered: July 2009
Location: Japan
Senior Member
>This functionality works wonderfully in IE and FF
Really? 'appendChild'-'getElementsByName' sequence doesn't work well in IE. (not knowing IE9)
<html>
<body>
<form></form>
<script type="text/javascript">
	var fld = document.createElement("input");
	fld.name = "test";
	document.getElementsByTagName("form")[0].appendChild(fld);
	alert(document.getElementsByName("test").length);
</script>
</body>
</html>

I got 0 on IE. (IE8 on WindowsXP)
This is known issue and you can see the solution at http://msdn.microsoft.com/en-us/library/ms536389%28v=VS.85%2 9.aspx
<html>
<body>
<form></form>
<script type="text/javascript">
	var fld1 = document.createElement("input");
	fld1.name = "test1";
	document.getElementsByTagName("form")[0].appendChild(fld1);
	alert(document.getElementsByName("test1").length);
	var fld2 = document.createElement("<input name='test2'>");
	document.getElementsByTagName("form")[0].appendChild(fld2);
	alert(document.getElementsByName("test2").length);
</script>
</body>
</html>

I got 0 and 1.
However, this is too bad since it violates DOM spec.(It causes "String contains an invalid character" exception on Firefox)

'getElementById' resolve it.
Previous Topic:How to connect to my local database server
Next Topic:Installation, grey screen when opening file
Goto Forum:
  


Current Time: Fri Apr 26 09:03:40 GMT 2024

Powered by FUDForum. Page generated in 0.03336 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top