471,887 Members | 725 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

error validating dynamic forms

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
1 1537
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.

Similar topics

10 posts views Thread by Brian Conway | last post: by
1 post views Thread by Lerp | last post: by
2 posts views Thread by Chris Dunaway | last post: by
reply views Thread by Gary Shell | last post: by
5 posts views Thread by ameen.abdullah | last post: by
1 post views Thread by =?Utf-8?B?bGpsZXZlbmQy?= | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.