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

Scott Brady evolt at scottbrady.net
Thu Dec 5 13:10:01 CST 2002

(reply to Hassan Schroeder's sample code)

We couldn't get the code you sent to work in Mozilla 1.1, so here's a sample of the code we're trying that doesn't work in Mozilla 1.1 (or 1.0).  Happen to spot anything wrong with it? (By doesn't work, I mean the dynamic form fields don't get submitted with the form)

---------------- BEGIN CODE ----------------
	<title>Dynamic Form Creation</title>

<cfsetting showdebugoutput="true">

<cfif isDefined("form.formHasBeenSubmitted")>

<script type="text/javascript">
	function addFormElements2(){
		place1 = document.getElementById('placeHolder1');
		newTextObj = document.createElement('input');

		place2 = document.getElementById('placeHolder2');
		place2.innerHTML = '<input type="text" name="dynamic2" value="test2">';


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


<form action="dynamicForm.cfm" method="post">
<input type="hidden" name="formHasBeenSubmitted">
	<td>First Name:</td>
	<td><input type="text" name="firstName"></td>
	<td>Last Name:</td>
	<td><input type="text" name="lastName"><input type="button" id="addEntry" value=" add field " onclick="addEntryField(this);" /></td>
	<td id="placeHolder1"></td>
	<td><a id="placeHolder2"></a></td>
	<td id="fieldCollection"></td>
	<td align="center" colspan="2"> <input type="submit" name="save"></td>
	<td align="center" colspan="2">&nbsp;&nbsp;</td>
	<td align="center" colspan="2">
	<button type="nothing" id="clickme" onclick="addFormElements2();return false">Add Dynamic Stuff</button>

---------------- END CODE ----------------

Scott Brady

More information about the thelist mailing list