Click to See Complete Forum and Search --> : How to append values to one variable


leonard905
10-13-2004, 10:29 AM
Hi all,

I stuck as to how to append the values from the form element below to one variable - e.

Please see code below:

<script>

var num = window.document.userGroups.elements.length
for (var i=0; i < num; i++)
{
var e = document.userGroups.elements[i].value;
alert(e) // I want e to be one long string with all the values in the loop.
}

</script>

<form name="userGroups">
<input type="hidden" name="group1" value="user1">
<input type="hidden" name="group2" value="user2">
<input type="hidden" name="group3" value="user3">
</form>

tomhartland
10-13-2004, 10:37 AM
var num = window.document.userGroups.elements.length
var e = "";
for (var i=0; i < num; i++)
{
e += document.userGroups.elements[i].value;
}
alert(e);

leonard905
10-13-2004, 10:45 AM
Thanks a bunch.