<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script>
function AddInput(k) {
var newSerial = document.createElement('input');
var newComment = document.createElement('input');
var newBreak = document.createElement('br')
newSerial.type = "text";
newComment.type = "text";
var parent = document.getElementById(k+"serial");
newSerial.id = "serial_"+k+"_"+eval("count"+k);
newComment.id = "comm_"+k+"_"+eval("count"+k);
eval("count"+k+"+=1");
//eval("dynamic" + i + " = val[i]")
parent.appendChild(newSerial);
parent.appendChild(newComment);
parent.appendChild(newBreak);
}
function GetSerials() {//data,radioAns) {
//THIS ALLOWS FUNCTIONALITY OF indexOF ON IE
if(!Array.indexOf){
Array.prototype.indexOf = function(obj){
for(var i=0; i<this.length; i++){
if(this[i]==obj){
return i;
}
}
return -1;
}
}
var counter = count = 0;
var k = 1;
var serials=[];
var comments=[];
var counters=[];
var elements=document.getElementsByTagName("input");
for (var i=0;i<elements.length;i++)
{
if (elements[i].id=="serial_"+k+"_"+counter)
{
if(elements[i].className == "size_"+k)
{
//alert("here");
if (serials.indexOf(elements[i].value)==-1)
{
count++;
}
else
{
alert("You can not use duplicate serial numbers - serial number "+elements[i].value+ " repeated");
elements[i].style.color = 'red';
return;
}
counter++;
}
k++;
}
}
}
</script>
</head>
<body>
<div id="1serial">
Serial:
Comment:<br/>
<input type="text" id="serial_1_0" class="size_1"/><input type="text" id="comm_1_0"/><br/>
</div>
<input type="button" value="Add Pipe" onclick="AddInput(1)"><br/>
<div id="2serial">
<strong>1502 Pipe 2' Joints</strong><br/>
Serial:
Comment:<br/>
<input type="text" id="serial_2_0" class="size_2"/><input type="text" id="comm_2_0"/><br/>
</div>
<input type="button" value="Add Pipe" onclick="AddInput(2)"><br/>
<!--There are "n" numbers of these-->
</body>
</html>
I have a number of those inputs and at the moment what Im trying to do is to count how many serial numbers of a particular size exists, but I cant seem to wrap my head around it. Thanks for your help.
well this info is going to be sent to a php file. The way this need to be sent is on 3 separate arrays, one with the counts of serials per size. This array will look like 3|2|3|...N.
The second array will have the size followed by the serials number, and will look like size1|serial1|serial2|serial3|size2|serial1|serial2|sizeN|serialN. The last one will be a collection of all comments whether they exist or not, this will look like com1|com2|com3.
So i think I am going to use getElementByClassName() to create the arrays of different elements.
Bookmarks