What is this “label”? Is it a DOM element? If so the “.label” bit is not the way to do things. Is it a child of “submitmessage”? Post some sample HTML which will help demurkify this.
You actually have to create the Label element first.
For this you need document.createElement. Then you can append the new text node to it, then append the label to the div. Try it and if it doesn’t work I’ll help you.
function show_error_body(label, msg){
removeChildren(label);
var labelerror = document.createElement(label);
document.getElementById("submitmessage").labelerror.appendChild(document.createTextNode(msg));
}
This also fails…
function show_error_body(label, msg){
removeChildren(label);
var labelerror = document.createElement(label).appendChild(document.createTextNode(msg));
document.getElementById("submitmessage").appendChild(labelerror);
}
No sorry. I must have missed your link. The code you recommend works but the label parameter was to removechildren first before adding the label again. In other words, if I click on the field and click off of it several times it will continue to add labels. I only want one of them to be added. For some reason it isn’t removing the previous label it just keeps adding them onblur. Any fix for this? Am I using the wrong parameters?
Here is my removechildren function
function removeChildren(element){
if (element.hasChildNodes())
{
while (element.childNodes.length >= 1)
{
element.removeChild(element.firstChild);
}
}
}
Dude - this onblur stuff is completely new to me. You really have to look at it from the perspective of someone who is not familiar with your application.
if I click on the field
What field? You need to provide the code that involves all of this stuff - including the onblur events and so on. But don’t post absolutely all your entire code and expect me to wade through it - that’s not what I’m asking.
Maybe you can do it yourself though - if you only want to create things once, you have to check if they’re there first. Have you tried that?