try this: loop each controls
form = document.forms[0];
myText = "";
for (var c = 0; c < form.elements.length; c++){
if (form.elements[c].type == 'textbox'){
if(form.elements[c].value != null){
myText = myText+form.elements[c].value + ",";
}
}
}
This isn't a Java question. Wrong forum. JavaScript != Java.
Use document.getElementsByName.
<html>
<head>
<script>
function showContents(fieldName)
{
var allTheBoxes = document.getElementsByName(fieldName);
if ( allTheBoxes == null )
return;
for ( var boxCount = 0; boxCount < allTheBoxes.length; boxCount++ )
{
alert("Value of textfield " + boxCount + ". : " + allTheBoxes[boxCount].value );
}
}
</script>
</head>
<body>
<table>
<tr>
<td>
<input type="text" name="namedBox" value="" />
</td>
</tr>
<tr>
<td>
<input type="text" name="namedBox" value="" />
</td>
</tr>
<tr>
<td>
<input type="text" name="namedBox" value="" />
</td>
</tr>
<tr>
<td>
<input type="text" name="namedBox" value="" />
</td>
</tr>
<tr>
<td>
<input type="text" name="namedBox" value="" />
</td>
</tr>
<tr>
<td>
<input type="text" name="namedBox" value="" />
</td>
</tr>
<tr>
<td>
<input type="button" name="checkFunction" value="Click Me" onclick="showContents('namedBox');" />
</td>
</tr>
</table>
</body>
</html>