[thelist] Inserting Form Fields with JS in Netscape 6+

Hassan Schroeder hassan at webtuitive.com
Thu Dec 5 12:41:00 CST 2002


Scott Brady wrote:

> Do you have an exampled of code where you're successfully using it?

Here's a somewhat stripped-down version of the function I'm using
(that should include all the relevant stuff):

function addEntryField(source)
{
	newInput = document.createElement("input");
	newInput.setAttribute("type", "text");
	newInput.setAttribute("name", "complements");
	document.getElementById("fieldCollection").appendChild(newInput);
	document.getElementById("fieldCollection").appendChild(source);
}

The function's called by a button that immediately* follows the last
existing text field --
	<input type="button"
		id="addEntry"
		value=" add field "
		onclick="addEntryField(this);" />

*immediately, as in >< -- bracket to bracket, or the prior sibling
is a text node, not the previous form element, and your selection
code gets a bit more complex.

And the second append (re)places the button after the new field.

HTH, let me know if any of that doesn't make sense.  :-)
--
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.






More information about the thelist mailing list