The DOM

Posted by Kumar Chetan on April 20, 2005

I was trying to generate some dynamic content using PHP MySQL. My client Mr. Raj was luking for some thing which will allow him to create and manage dynamic forms. Also he along with little bit of my interfernce designed a database. this database was meant to grab evvery bit of info related to a user. Is he/she mrried? Spourse employed? got children? If yes then age name sex. Have u got fone? if yes then which? Cellular/Landline/this that …..
Now when I am trying to grab info regarding a fone no then I need a mechanism that will allow User to keep adding the fields till he/she wants and then press submit. I had planned it to be like the contact book of Gmail. How do I do this????
Answer is DOM. create a node and then keep duplicating it. simple.
Check this code

var fieldcounter = 0;
function moreFields(whichfield,wheretoadd){
fieldcounter++;
newFields = document.getElementById(whichfield).cloneNode(true);
newFields.id = ”;
newFields.style.display = ‘block’;
var newField = newFields.childNodes;
for (var i=0;i
var theName = newField[i].name
if (theName) newField[i].name = theName + fieldcounter;
}
var insertHere = document.getElementById(wheretoadd);
insertHere.parentNode.insertBefore(newFields,insertHere);
}

BTW I dont own copy right to this function. I copied it shamelessy from www.quirksmode.org/. Its the best site for anyone who has been harassed by crossbrowser compatibility issue.
Infact I have never used JS Dom behaovours. I thot them to be some alien things.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments


Fine Print: In very short I own my views & if you don't like something on my blog, I am sorry, I can't help you. In fact I am not even sorry. Ch33r5.