473,597 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

removing a node.

I have written a simple function that validates a form based on the form
objects' className attribute. The form basically write a "field
required" message next to the form element that is blank(and is
required). I have implemented all the Regex stuff onload already.

function checkRequired(v arForm){
var varReturn = true;
for(var i=0; i<varForm.lengt h; i++){
if(varForm.elem ents[i].className.inde xOf('required') != -1 &&\
varForm.element s[i].value == ""){
varSpan=documen t.createElement ('span');
varMsg=document .createTextNode ('* This field is required!');
varSpan.appendC hild(varMsg);
varSpan.setAttr ibute("class", "error");
varForm.element s[i].parentNode.app endChild(varSpa n);
varReturn = false;
}
}
return varReturn;
}

I am having difficulty removing the new nodes I have created. Each time
I click submit, I want the nodes I created to be removed, otherwise I
just keep on appending the same message string each time. Any suggestions?
Jul 23 '05 #1
2 1532


bmgz wrote:
I have written a simple function that validates a form based on the form
objects' className attribute. The form basically write a "field
required" message next to the form element that is blank(and is
required). I have implemented all the Regex stuff onload already.

function checkRequired(v arForm){
var varReturn = true;
I don't think it makes sense to prefix any variable name with var,
instead that makes reading the code harder.
for(var i=0; i<varForm.lengt h; i++){
if(varForm.elem ents[i].className.inde xOf('required') != -1 &&\
varForm.element s[i].value == ""){
varSpan=documen t.createElement ('span');
You need to somewhere store those elements you create, either use an
array that is associated with the form e.g.
varForm.validat ionSpans = [];
and add those spans as needed e.g.
varForm.validat ionSpans[varForm.validat ionSpans.length] = varSpan;
or associate each span with the element e.g.
varForm.element s[i].validationSpan = varSpan;
The later on you can remove those spans, removing an element is as easy as
element.parentN ode.removeChild (element);
varMsg=document .createTextNode ('* This field is required!');
varSpan.appendC hild(varMsg);
varSpan.setAttr ibute("class", "error");


Doing
varSpan.classNa me = "error"
is the preferred way as it works with both IE and other browsers while
using setAttribute with IE would require setAttribute("c lassName", "error")
to work.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Martin Honnen wrote:
I don't think it makes sense to prefix any variable name with var,
instead that makes reading the code harder.
I am used to $variablename, trying to establish some new bad habits as I
am new to JS ;-)
You need to somewhere store those elements you create, either use an
array that is associated with the form e.g.
varForm.validat ionSpans = [];
and add those spans as needed e.g.
varForm.validat ionSpans[varForm.validat ionSpans.length] = varSpan;
or associate each span with the element e.g.
varForm.element s[i].validationSpan = varSpan;
The later on you can remove those spans, removing an element is as easy as
element.parentN ode.removeChild (element);

dynamite, thanks.
varSpan.classNa me = "error"


thanks for that, I think it was like that, then I changed it for no
particular reason..
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3121
by: Jimmy | last post by:
Hi everyone, I am working with a binary tree, and I am having a bit of trouble visuallizing what needs to happen when I am trying to delete a node that has two children. (no child node and one child node were trivial). Does anyone know the solution to this problem? void CTree::Delete(CPerson *&pPerson)
4
12579
by: Grant Wagner | last post by:
There doesn't seem to be any mechanism to "clear" a node of all it's children (not that its necessary very often, but I have come across situations where I'd like to clear a node of all it's children before appending other nodes). I've come up with two possibilities: function removeAllChildNodes(node) { if (node && node.hasChildNodes && node.removeChild) { while (node.hasChildNodes()) { node.removeChild(node.firstChild);
2
2691
by: Raja Kannan | last post by:
Is there a way to remove text portion from the HTML keeping the HTML Tags using the browser, say javascript RegEx or something ? I have seen lot of examples removing HTML tags to get the text but how the reverse of it ? any sample code or any suggestion would be appreciated.
3
16030
by: e-mid | last post by:
Here is an xml structure. i want to remove <a> nodes that do not have any child. How can i do that in csharp? <root> <a> <b/> </a> <a/> <a/> <a> <c/>
2
10681
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this attribute and remove the containing node (and child nodes) if it has a certain value. I'm able to find the attributes using an XmlTextReader. Once found, can someone help me get the XPath at that point? I would then use this to remove the node from...
7
2970
by: Simon Hart | last post by:
Hi, I have a requirement to remove the xmlns from the DOM in order to pass over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if there is a xmlns present!?! The reason I have a xmlns present is because the Xml I am passing to CRM is a node from a bigger file that does require a xmlns and using the DOM ..OuterXml seems to set the xmlns for you automatically - which I don't want. Any help would be great.
0
1299
by: jonny | last post by:
Hi, I have a template "delete-node" with two arguments containing document fragments when called. I want to return a new document fragment which contains all nodes from argument 2 except the one which is contained in argument 1. The code currently looks like this:
5
7814
WebDunce
by: WebDunce | last post by:
Hi guys, I am trying to develop a simple xml editor. I have an object that has a TreeView. I use the TreeView to display the Xml node info. That's all fine, but i want the user to be able to move the actual xml nodes about by interacting with the non-xml TreeView nodes. my basic algorithm is as follows: user has selected a treeview node if user presses Ctrl+Up Arrow, then
0
1023
by: jambalapamba | last post by:
Hi I am removing node from a document depending on the style property and this is taking 7 seconds for checking complete document is there any ideas how can i improve the perfomance. Here is my part of code foreach (IHTMLElement tempElement in document.all) { if (tempElement.style.visibility == "hidden" ) { IHTMLDOMNode node = tempElement as...
2
12885
by: MedIt | last post by:
Hi, I am new in using xsl.I am stuck in a simple task,which is trying to remove an atribute from a node,and keep the rest of the attributes of this element in the xslt. I have tried a couple of options but to no use so far! Can any one shed some light on me? Here's a sample of my original xml: <?xml version="1.0" encoding="UTF-8" ?> <dom xmlns="http://www.cdisc.org/ns/odm/v1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"...
0
7962
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7884
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8267
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8024
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5844
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5423
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3880
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2394
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.