B
Ben Hallert
Hi guys,
I'm trying to figure out what bone headed mistake I made on something I
put together. I've got a form (named 'context') that has a variable
number of select-multiple inputs on it. Based on the number of
variables passed through a GET string, I want to multiply the total
number of selected items for each together to see how many possible
combinations the selected items are generating.
The following snippet of code succesfully gets the values from the GET
statement to count the number of items being passed (I know, it assumes
the variable will always be in the same place, I'll deal with that
later), then it's supposed to loop through all elements in the page.
If the item it finds is a select-multiple input (up to this point, it
works. It finds each select-multiple and alerts in debugging), it's
supposed to do a loop inside that element to count how many are
checked, then multiply it against the running total (which is named
predictioncount). I expect the number for predictioncount to be 0
until the last field has an entry in it, but it never stops being
anything BUT zero.
I'm no Javascript expert, and my kludgy code shows it, but I think I'm
close to this functioning and I'm hoping someone here will see and say
"Oh, you got the standard whatsit confused with the thingy, just change
character x to y and it should work".
Thanks in advance for any assistance!
function trackselections()
{
//We'll get the variable passed, then get the name of it. If the item
is selected, we add one to the item. If not, we subtract it
//This lets us map out what will be submitted and calculate complexity
based on that.
var num = document.context.length;
var count=0;
var predictioncount = 0;
var testunit_count = 0;
//First, count how many testcase_ids are passed.
var getstring = location.search.substr(1);
var testunit_ids = 0;
count = getstring.search(/\&/);
getstring = getstring.substr(13,count-13);
testunit_ids = getstring.split(/%2C/g);
testunit_count = testunit_ids.length;
//Next, count all inputs of of the type select-multiple and loop
through them,
//collecting info on how many items are checked
for (var i = 0; i < num; i++)
{
if (document.context.type == 'select-multiple')
{
count = 0;
for (var o = 0; o< document.context.length; o++)
{
if (document.context.id[o].selected) count++;
alert(count);
}
predictioncount = predictioncount * count;
}
alert(predictioncount);
}
}
I'm trying to figure out what bone headed mistake I made on something I
put together. I've got a form (named 'context') that has a variable
number of select-multiple inputs on it. Based on the number of
variables passed through a GET string, I want to multiply the total
number of selected items for each together to see how many possible
combinations the selected items are generating.
The following snippet of code succesfully gets the values from the GET
statement to count the number of items being passed (I know, it assumes
the variable will always be in the same place, I'll deal with that
later), then it's supposed to loop through all elements in the page.
If the item it finds is a select-multiple input (up to this point, it
works. It finds each select-multiple and alerts in debugging), it's
supposed to do a loop inside that element to count how many are
checked, then multiply it against the running total (which is named
predictioncount). I expect the number for predictioncount to be 0
until the last field has an entry in it, but it never stops being
anything BUT zero.
I'm no Javascript expert, and my kludgy code shows it, but I think I'm
close to this functioning and I'm hoping someone here will see and say
"Oh, you got the standard whatsit confused with the thingy, just change
character x to y and it should work".
Thanks in advance for any assistance!
function trackselections()
{
//We'll get the variable passed, then get the name of it. If the item
is selected, we add one to the item. If not, we subtract it
//This lets us map out what will be submitted and calculate complexity
based on that.
var num = document.context.length;
var count=0;
var predictioncount = 0;
var testunit_count = 0;
//First, count how many testcase_ids are passed.
var getstring = location.search.substr(1);
var testunit_ids = 0;
count = getstring.search(/\&/);
getstring = getstring.substr(13,count-13);
testunit_ids = getstring.split(/%2C/g);
testunit_count = testunit_ids.length;
//Next, count all inputs of of the type select-multiple and loop
through them,
//collecting info on how many items are checked
for (var i = 0; i < num; i++)
{
if (document.context.type == 'select-multiple')
{
count = 0;
for (var o = 0; o< document.context.length; o++)
{
if (document.context.id[o].selected) count++;
alert(count);
}
predictioncount = predictioncount * count;
}
alert(predictioncount);
}
}