You can declare id variable as global in init() method as call it onload of body tag
function init()
{
id =0;
}
then append id to text box id property which u dynamically created.
Declare a combo Box of name fileNames. as
<html:select property="fileNames" multiple="true">
<html:option value="">-Select-</html>
</html:select> when You submit form you can use
function submit(form)
{
var newElem="";
for(int j=0;j<id;j++)
{
newElement =document.createElement("<OPTION>");
var textBox1=document.getElementById("alertFieldName"+id);
newElement.text=textBox1.value;
newElement.value=textBox1.value;
form.fileNames.options.add(newElement);
}
for(var i=0;i< form.fileNames.options.length;i++)
{
form.fileNames.options.selected=true;
}
}