Page 1 of 1

DHTML/DOM appendChild() problem

Posted: Thu Dec 26, 2002 8:18 pm
by evildoppler
Hey guys!
I've been hunting a bit of information in my quest to finally learn DHTML and to utilise the DOM more effectively.
Anyways, got into a bit of a problem that I don't seem to be able to "study" my way out of.

The problem is simple, annoying but simple.

I'm creating an element - in this case an input field and appends it to a <form> so that the <form> won't ignore the input field.

So what happens is that it will - depending on browser used - make the input field appear at the top of the form (before any other input element) or at the bottom (after any other input element).

The problem I have is that i need this input field to appear at a certain point - within a specific <div>.

Now, normally I'd just have appended the input field to the div BUT in doing that i'll loose the input field from the form during submission.

To give you a better understanding of what i'm attempting here.

Code: Select all

function AddInputField(foo) &#123;

  if (ns6) &#123;
	ElementPresent = (document.getElementById('newInputField'))? true:false;
  &#125;
  else if (ie4) &#123;
	ElementPresent = (document.all&#1111;"newInputField"])? true:false;
  &#125;
  else if (ns4) &#123;
	ElementPresent = (document.layers&#1111;"newInputField"])? true:false;
  &#125;

if (!ElementPresent) &#123;
 var inputElement = document.createElement("input");
 inputElement.setAttribute("id","newInputField");
 inputElement.setAttribute("name","newInputField");
 
 var targetDiv = document.createElement("div");
 targetDiv.setAttribute("id","targetDiv");
	 		 
	 if (foo == "other") &#123;
	 	if (ie4) &#123;
		  document.all&#1111;"select"].appendChild(targetDiv);
		  document.all&#1111;"submitForm"].appendChild(inputElement);	
		&#125;
		else if (ns4) &#123;
		  document.layers&#1111;"select"].appendChild(targetDiv);
		  document.layers&#1111;"submitForm"].appendChild(inputElement);
		&#125;	 
		else if (ns6) &#123;
		document.getElementById('select').appendChild(targetDiv);
		document.getElementById('submitForm').appendChild(inputElement);
		&#125;	
	 &#125;
 &#125;
 else &#123;
 	if (foo != "other") &#123;	
	   if (ie4) &#123;
		 var node1 = document.all&#1111;"submitForm"];
	          var node2 = document.all&#1111;"newInputField"];
                   var exe = node1.removeChild(node2);
		&#125;
		else if (ns4) &#123;
		 var node1 = document.layers&#1111;"submitForm"];
		 var node2 = document.layers&#1111;"newInputField"];
		 var exe = node1.removeChild(node2);
		&#125;	 
		else if (ns6) &#123;
		  var node1 = document.getElementById('submitForm');
		  var node2 = document.getElementById('newInputField');
		  var exe = node1.removeChild(node2);
		&#125;
	   &#125;
      &#125;
&#125;
So, basically what i'm doing there is to create an element (input field) when a specific function is called.

easy...or so i thought!!!

Anyways, if there's any smart cookies out there that could give me a hand then that would be appreciated.

Cheers and Happy Christmas and Merry New Year

Posted: Fri Dec 27, 2002 4:43 pm
by evilcoder
a more pressing issue lays here..... Why have you got evil at the start of your name?......... :twisted:

latest issue

Posted: Sun Dec 29, 2002 5:21 pm
by evildoppler
Well, I guess it can appear to you that i've "stolen" part of your name - though, i've been using this name since 1995 I can definitely assure you that there's no "theft" involved.

Other than that, I don't really see an issue here.