Ok, well I didn't use onLoad, because I don't really know how to use it just yet...
But here's what I have, it DOESNT work, but it's what I have in mind. I am using "onLoad" in the INPUT tags
*ONLY* as a placeholder because I don't know how to call the function within the INPUT tags.
JS:
Code:
<script type="text/javascript">
var countCheck = 0;
var countRadio = 0;
var countInput = 0;
var getCheck = document.getElementsByName('checkbox');
var getRadio = document.getElementsByName('radio');
var getInput = document.getElementsByTagName('input');
function countMe(type){
if(type == document.getElementsByName('checkbox')) countCheck += 1;
if(type == document.getElementsByName('radio')) countRadio += 1;
}
countInput = (countCheck + countRadio);
document.write('There are: ' +countCheck+ ' checkboxes <br />');
document.write('There are: ' +countRadio+ ' radio buttons <br />');
document.write('There are a total of: ' +countInput+ ' input types <br />');
</script>
HTML:
Code:
<body>
<div><input type="checkbox" name="checkbox" value="checkbox" onLoad="countMe(this)" /></div>
<div><input type="checkbox" name="checkbox" value="checkbox" onLoad="countMe(this)" /></div>
<div><input type="checkbox" name="checkbox" value="checkbox" onLoad="countMe(this)" /></div>
<div><input type="radio" name="radio" onLoad="countMe(this)" /></div>
<div><input type="radio" name="radio" onLoad="countMe(this)" /></div>
<div><input type="radio" name="radio" onLoad="countMe(this)" /></div>
</body>
So now I will explain my intentions.
As each element loads, it calls the "countMe" function.
I use the "this" to dynamically tell the function what type of element it is.
The function then just takes a look at what element it is, and adds "1" to the correct counter.
Is what I'm doing possible? How do you call a function within the INPUT tags? Everything I've looked up, it's always based on some kind of event like onClick, onFocus etc...
Is there any
"passive" way to call a function without user input?