2 Replies - 3559 Views - Last Post: 26 August 2010 - 07:55 PM

#1 shinjie2554  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 28-August 09

Adding Element and placing it as the first form child element

Posted 26 August 2010 - 07:32 PM

Hi guys, I have a javascript here for adding my div element to my registration form,
Adding the div element is easy, but it shows on the bottom of my form. I cant make it as the first child element of my form...
thanks...

Ay suggestions?

This is my code

var _form = document.getElementById('registration_form');
var errorDiv = document.createElement('div');

errorDiv.setAttribute('class', 'confBox');
errorDiv.innerHTML= "<strong>There is already an existing account for " + _form.email.value + ". Please login.</strong><br/>";

_form.appendChild(errorDiv);  		
return false;


This post has been edited by Martyr2: 26 August 2010 - 07:49 PM
Reason for edit:: Please use code tags in the future, thanks!


Is This A Good Question/Topic? 0
  • +

Replies To: Adding Element and placing it as the first form child element

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4337
  • View blog
  • Posts: 12,137
  • Joined: 18-April 07

Re: Adding Element and placing it as the first form child element

Posted 26 August 2010 - 07:48 PM

The method appendChild appends... which means adds to the end of. If you want to add to the beginning then try the method insertBefore().

formContainer.insertBefore(childElementHere, formContainer.firstChild);



In other words, insert the child element before the first child of the parent container. Hope that makes sense to you! Enjoy!



"At DIC we be insertBefore using code ninjas... insert us before everyone else because we are that leet." :snap:
Was This Post Helpful? 1
  • +
  • -

#3 shinjie2554  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 28-August 09

Re: Adding Element and placing it as the first form child element

Posted 26 August 2010 - 07:55 PM

View PostMartyr2, on 26 August 2010 - 06:48 PM, said:

The method appendChild appends... which means adds to the end of. If you want to add to the beginning then try the method insertBefore().

formContainer.insertBefore(childElementHere, formContainer.firstChild);



In other words, insert the child element before the first child of the parent container. Hope that makes sense to you! Enjoy!



"At DIC we be insertBefore using code ninjas... insert us before everyone else because we are that leet." :snap:


This is GREAT Martyr!
I will try this thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1