<html>
<head>
<title></title>
<style>
.delcell {
border-style: solid;
border-color: #000000;
border-bottom-width: 1px;
border-left-width: 0px;
border-right-width: 0px;
border-top-width: 0px;
}
.partcell {
border-style: solid;
border-color: #000000;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
border-top-width: 1px;
}
</style>
<script language="javascript">
var arrParts = new Array();
function addrow(which)
{
if (which.value != 0)
{ //Add value and text from listbox as well as current date to the arrParts array.
var today = new Date();
var year = today.getYear()
var shortdate = ((today.getMonth()+1) + "/" + today.getDate() + "/" + (year+"").substring(2,4));
var arrRow = arrParts.length;
arrParts[arrRow] = which.value;
arrParts[arrRow+1] = (which.options(which.selectedIndex).text);
arrParts[arrRow+2] = shortdate;
showtable();
}
}
function showtable()
{ //Removes existing rows of data from table and then rebuilds the table with updated info from arrParts.
var lastRow = 2; //Starts at 2 so the title and header rows do not get deleted.
var mytable = document.getElementById('SelectedParts');
//First, remove all previously created cells except the title and headers.
var delRows = mytable.rows.length;
for (var loop=delRows;loop>2;loop--)
{
mytable.deleteRow(loop-1);
}
//Now rebuild the rows with information from arrParts.
if (arrParts.length / 3 >= 2)
var arrlength = (arrParts.length / 3) - 1;
else
arrlength = 0;
for (loop=0;loop<arrParts.length;loop++)
{
var row = mytable.insertRow(lastRow);
var delrow='<font color="#0000A0"><a onmouseover="this.style.cursor=\'hand\'; this.style.color=\'red\'" onmouseout="this.style.cursor=\'auto\'; this.style.color=\'0000A0\';" onclick="removerow(' + loop + ');">Del</a></font> ';
// first cell
var cell1 = row.insertCell(0);
cell1.innerHTML=delrow;
cell1.setAttribute("className", "delcell");
// second cell
var cell2 = row.insertCell(1);
cell2.innerText=arrParts[loop];
cell2.setAttribute("className", "partcell");
// third cell
var cell3 = row.insertCell(2);
cell3.innerText=arrParts[loop+1];
cell3.setAttribute("className", "partcell");
// fourth cell
var cell4 = row.insertCell(3);
cell4.innerText=arrParts[loop+2];
cell4.setAttribute("className", "partcell");
lastRow++;
loop=loop+2;
}
}
function removerow(which)
{ //Remove row of data from arrParts when Del is selected next to that row in table.
var whichrow =
arrParts.splice(which, 3);
showtable();
}
function createhidden()
{ //Create hidden Input fields for selected data before submitting form.
//Fields are named Partsx with x representing the array position the data came from.
//Each record contains 3 pieces of data, Part number, description and date. Arrays start at 0.
//So the first record will be contained in hidden fields Part0, Part1 and Part2. This makes it easy
//to read the fields dynamically from the script you post this data to.
//The total number of hidden Parts fields created will be stored in field HiddenTotal so you know how much
//data to read in on the next page. This value also starts at 0 so a value of 8 means there are 9 fields to read.
var myform = document.getElementById('SubmitData');
document.getElementById('HiddenTotal').value = arrParts.length-1;
if (arrParts.length >0)
{
for (var loop=0;loop<arrParts.length;loop++)
{
var fieldname = "Part" + loop;
var fileinput = document.createElement("input");
fileinput.type = "hidden";
fileinput.id = fieldname;
fileinput.name = fieldname;
fileinput.value = arrParts[loop];
myform.appendChild(fileinput);
}
}
}
function isready()
{ //If you place any calls in here to do validation, execute it prior to calling createhidden.
//Otherwise you might create hidden fields, error so the form does not submit and then when it is submitted
//again it would create more hidden fields with an identical name.
createhidden(); //Create hidden fields before submitting.
return true; //Allow form to submit. Setting to false will prevent submission.
}
</script>
<body>
<div align="center">
<form id="SubmitData" method="post" action="mypage.asp" onsubmit="return isready()" >
<input id="HiddenTotal" type="hidden" value="">
<table id="SelectedParts" border="0" width="600" cellspacing="0" cellpadding="0">
<tr>
<td width="600" colspan="4" style="text-align: center; font-weight: bold">Part Selection</td>
</tr>
<tr>
<td width="40"></td>
<td width="150"
style="text-align: center; font-weight: bold; border: 1px solid rgb(0,0,0)">Part Number</td>
<td width="260"
style="text-align: center; font-weight: bold; border: 1px solid rgb(0,0,0)">Description</td>
<td width="150"
style="text-align: center; font-weight: bold; border: 1px solid rgb(0,0,0)">Date</td>
</tr>
</table>
</center>
<table border="0" width="600" align="center">
<tr>
<td height="15"></td>
</tr>
<tr>
<td align="center"><select name="PartsList" size="1" onchange="addrow(this)">
<option value="0">Select a Part</option>
<option value="1001">Part1</option>
<option value="1002">Part2</option>
<option value="1003">Part3</option>
<option value="1004">Part4</option>
<option value="1005">Part5</option>
</select> </td>
</tr>
</table>
<br><br>
<center><input type="Submit" value="Submit"></center>
</form>
</center></div>
</body>
</html>