By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,995 Members | 1,090 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,995 IT Pros & Developers. It's quick & easy.

error validating dynamic forms

P: n/a
I have a form in which I am generating dynamic fields. I can do this
fine, but when I go to validate them there are errors. The non-
dynamic fields validate correctly. Below is the html and js. Can
someone explain why the dynamic field is failing, and what I can do to
correct it? I can tell as much that the validation fails when
testing: "if (!elem.firstChild)"

<script type="text/javascript" src="dynamicFields.js"></script>
<script type="text/javascript" src="validateScripts.js"></script>
.info { color: black; background-color: transparent; font-weight:
.warn { color: rgb(120,0,0); background-color: transparent; font-
weight: bold;}
.error { color: red; background-color: transparent; font-weight:

<input type=text name=number size=3 value=1>
<input type=button value="update" onClick="addField(number.value);">

<td>Below field will <b>NOT</bvalidate correctly</td>
<span id=fieldHolder style="position:relative;"></span>

<td>Below field will validate correctly</td><td></td>
<td><input type="text" id="works"
<td id="inf_works">&nbsp;</td>


======= validateScripts.js =======
var nbsp = 160;
var node_text = 3;
var emptyString = /^\s*$/ ;

function msg (fld, msgType, message)
var elem = document.getElementById(fld);
elem.firstChild.nodeValue = message;

elem.className = msgType;

function validate(valField,infoField)
var elem = document.getElementById(infoField);
if (!elem.firstChild) return true;
if (elem.firstChild.nodeType != node_text) return true;

valField.value = valField.value.toUpperCase();

if (emptyString.test(valField.value))
msg(infoField,"error","No Data?");
return false;
msg(infoField,"warn","WARN: some data changed");

return true;
======dynamicFields.js ======
function addField(number)
var data;

data = '<td><input type="text" id="notWork" onChange="validate(this,
data = data + '<td id="inf_notWork">&nbsp;</td>';
fieldHolder.innerHTML = data;

May 4 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Can you not perform .firstChild on a dynamic object? I know the
object exists, and if I play with the validate function, I can see the
text in the user field. I don't understand why the firstchild of the
label can't be accessed.

May 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.