Ok so I gave myself a simple project...I have 6 input types.
3 are of type radio, and the other 3 are checkboxes.
JS:
Code:
<script type="text/javascript">
var getCheck = document.getElementsByName('checkbox');
var getRadio = document.getElementsByName('radio');
var getInput = document.getElementsByTagName('input');
document.write('There are: ' +getCheck.length+ ' checkboxes');
document.write('There are: ' +getRadio.length+ ' radio buttons');
document.write('There are a total of: ' +getInput.length+ ' input types');
</script>
HTML:
Code:
<body>
<div><input type="checkbox" name="checkbox" value="checkbox" /></div>
<div><input type="checkbox" name="checkbox" value="checkbox" /></div>
<div><input type="checkbox" name="checkbox" value="checkbox" /></div>
<div><input type="radio" name="radio" /></div>
<div><input type="radio" name="radio" /></div>
<div><input type="radio" name="radio" /></div>
</body>
My output is:
There are: 0 checkboxes
There are: 0 radio buttons
There are a total of: 0 input types
I thought that the "getElementsByName and getElementsByTagName" were arrays? So I thought I could just use the ".length" to get the count?
So anyways, the output is suppose to say:
There are 3 checkboxes.
There are 3 radio buttons.
There are a total of: 6 input types.