Click to See Complete Forum and Search --> : Accessing input values inside a div


mili
08-05-2003, 07:23 PM
Hi,

I have some div's which have autogenerated id's like div1, div2,div3 etc. Each of these div's contain a few input fields.Based on the user's selection from a dropdown box, I hide all the other divs and show only the div that the user has selected.Now I want to loop thro' all the fields only from the current div and concatenate them into a string.How can I do this?

Thanks

Khalid Ali
08-05-2003, 10:23 PM
//get the reference to the div

var divObj = document.getElementById("div1);

//now get a list of input elements children of this div

var children = divObj.getElementsByTagName("input");

now loop through the list

for var x=0;x<children.length;x++){
var el = children[x];
//el.value
}

mili
08-06-2003, 08:54 PM
That was brilliant!

It works like a charm for me :)

Thanks Khalid

Khalid Ali
08-06-2003, 09:07 PM
:D
My pleasure