/    Sign up×
Community /Pin to ProfileBookmark

need help collecting data

this is part of the code

[CODE]<!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: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
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: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
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>[/CODE]

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.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@xelawhoApr 18.2012 — let's start with some code that actually works, like I showed you a month ago:

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<style type="text/css">
#serial,#comment{
float:left;
}
#butt{
clear:both;
}
</style>

</head>
<body>
<div id="serial">
Serial:<br><input type="text" class="serials"/>
</div>
<div id="comment">
Comment:<br><input type="text"/>
</div>
<div id="butt">
<input type="button" onclick="checkDupes()" value="Add pipe"/>
</div>
<script>

var serials=[];
function checkDupes(){
var tbs=document.getElementsByTagName("input");
serials.length=0;
for (var i = 0; i < tbs.length; i++) {
if (tbs[i].type=="text"&&tbs[i].className=="serials"){
tbs[i].style.color="black"
if(!Array.indexOf){
Array.prototype.indexOf = function(obj){
for(var i=0; i<this.length; i++){
if(this[i]==obj){
return i;
}
}
return -1;
}
}
if (serials.indexOf(tbs[i].value)==-1){
serials.push(tbs[i].value);
} else {
alert("You can not use duplicate serial numbers - serial number "+tbs[i].value+ " repeated");
tbs[i].style.color="red"
return;
}
}
}
var newSerial = document.createElement('input');
var newComment = document.createElement('input');
var serBreak = document.createElement('br');
var comBreak = document.createElement('br')
newSerial.type = "text";
newSerial.className = "serials";
newComment.type = "text";
var serdiv = document.getElementById("serial");
var comdiv = document.getElementById("comment");
newSerial.id = "serial_"+serials.length;
newComment.id = "comm_"+serials.length;
serdiv.appendChild(serBreak);
comdiv.appendChild(comBreak);
serdiv.appendChild(newSerial);
comdiv.appendChild(newComment);

}


</script>
</body>
</html>
[/CODE]


now what was it that you wanted to do?
Copy linkTweet thisAlerts:
@blak422authorApr 19.2012 — 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.
Copy linkTweet thisAlerts:
@xelawhoApr 19.2012 — So i think I am going to use getElementByClassName() to create the arrays of different elements.[/QUOTE]
thus excluding anyone using <IE9 from interacting with your database?

but more importantly, if you have code that prevents users from entering the same serial number, won't the "serials per size" always be 1|1|1?
×

Success!

Help @blak422 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...