473,396 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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)"

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

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

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

<table>
<tr>
<td>Below field will validate correctly</td><td></td>
</tr>
<tr>
<td><input type="text" id="works"
onchange="validate(this,'inf_works');"></td>
<td id="inf_works">&nbsp;</td>
</tr>
</table>

</body>
</html>

======= 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);
alert('a');
if (!elem.firstChild) return true;
alert('b');
if (elem.firstChild.nodeType != node_text) return true;
alert('c');

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

if (emptyString.test(valField.value))
{
msg(infoField,"error","No Data?");
return false;
}
else
{
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,
\'inf_notWork\');"></td>';
data = data + '<td id="inf_notWork">&nbsp;</td>';
fieldHolder.innerHTML = data;
}

May 4 '07 #1
1 1600
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
10
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through...
1
by: Lerp | last post by:
Hi all, What do I have to do in order to get my value from my textbox that is formatted like 'mm/dd/yyyy' into a datetime database field ? Currently getting an error: Syntax error converting...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
2
by: gmccallum | last post by:
I have a data entry screen using controls bound through a bindingSource, TableAdaptor and a BindingNavigator to move through the records. When I have an data entry error (such as Null for a value)...
5
by: ameen.abdullah | last post by:
Hi Guys, I have a textbox in windows form that should only accept alphabets, numbers, spaces and underscore. If the textbox contains anyother character it should display a msg at the time of...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.