Hi,
I want to write a JSP/Struts 1.x code to upload a file along with other form fields.
Something like this:
<input type="text" name="name" />
<select name="edu">
<option>....</option>
<option>....</option>
<option>....</option>
</select>
<input type="file" name="fileupld" />
Important thing is that these three fields can be added multiple times to the form, just like add new row for adding more records.
I do that using simple javascript:
function addRow() {
var tbl = document.getElementById('tbl');
var Row = parseInt(document.getElementById('hsb').value);
var temprow=Row+1;
var mainRow = tbl.insertRow(temprow);
var trId ="tr"+temprow;
mainRow.id=trId;
var td = document.createElement("td");
td.colSpan='3';
var table = document.createElement("table");
table.border="0";
table.cellPadding="0";
table.cellSpacing="1";
table.width="100%";
var newRow = table.insertRow(0);
var sec = "'risk'";
var newCell = newRow.insertCell(0);
newCell.width="10%";
newCell.innerHTML = '<input type="text" class="input" name="regnNo'+temprow+'" id="regnNo'+temprow+'" value="" size="12" maxlength="12 ">';
var newCell = newRow.insertCell(1);
newCell.width="10%";
newCell.innerHTML = '<select class="input" name="regnYr"'+temprow+' id="regnYr'+temprow+'" ><option value="2001">2001</option></select> '+
'<select name="regnMonth'+temprow+'" class="input" id="regnMonth'+temprow+'"><option value="1">Jan</option><option value="2">Feb</option><option value="3">Mar</option><option value="4">Apr</option>'+
'<option value="5">May</option><option value="6">Jun</option><option value="7">Jul</option><option value="8">Aug</option>'+
'<option value="9">Sep</option><option value="10">Oct</option><option value="11">Nov</option><option value="12">Dec</option></select>';
var newCell = newRow.insertCell(2);
newCell.width="15%";
newCell.innerHTML = '<input type="file" class="input" name="image'+temprow+'" id="image'+temprow+'" value="Select File" />';
td.appendChild(table);
mainRow.appendChild(td);
document.getElementById('hsb').value=temprow;
}
The above addRow is working fine and I am able to generate multiple rows.
But, when I try to submit the for I am not getting all the fields to my servlet.
I don't know what is happening.
Can any of you give me a simple solution how to upload the file as well as other form fields with multiple rows.
Thanks
request.getParameterValues
request.getParameterValues
request.getParameterValues
request.getParameterValues
Open in new window