04-22-2009, 09:17 PM
|
#9 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Salathe
javascript Code:
/* Don't be lazy! */ ++retval[elements[n].type.toLowerCase()];
|
haha, you guys crack me up...
Ok, so it works now, I see where you went with the code. Although the "output" is written up on top, by using the Render() function after the elements have already loaded, you can now output the correct number of elements instead of diplaying 0.
gotchya...I have some questions about the CategorizeInputFields function, so I'll break it down here....
I am unsure of what is going on here. You create a variable called "retval" which I assume is short for "Retrieve Values".
Is this an array or are we creating an object?
Code:
var retval =
{
'checkbox': 0,
'radio': 0,
'total': 0
};
Are we passing "document.getElementsByTagName" to this conditional and if it doesn't exist we return nothing??
Code:
/* Browser does not support getElementsByTagName, return void */
if(!document.getElementsByTagName)
{
return(retval);
}
Here we get all the of the input tags, then count them and assign the count to retval.total
Code:
var elements = document.getElementsByTagName('input');
retval.total = elements.length;
return void, if no total from document.getElementsByTagName('input') return nothing?
Code:
/* No input tags in tree */
if(!retval.total)
{
return(retval);
}
declare "n" var and set to 0. If less than the total number of input elements, keep looping. Using the PRE-increment operator. Set all of the elements to lowercase to support all browser types with toLowerCase().
You then find the element type with: elements[n].type.
The [n] is just the increment for each type of element.
I know that this "The ++retval[]" is PRE-incrementing the element value and then returning it to the function (retval), but can someone explain to my how it works exactly?
The format just looks foreign to me...
Code:
for(var n = 0; n < retval.total; ++n)
{
++retval[elements[n].type.toLowerCase()];
}
return(retval);
let me know if I got most of the code right?
Thanks!
|
|
|
|