I am new to Javascript so I'm not sure if my code is working as I'm not sure how to test or run it. What I want my code to do is display the JSON created from gathering all the checked boxes. I haven't added a console.log anywhere because I'm not sure where it would be appropriate. I feel as though I have all the pieces but I am not sure how to put everything together.
The expected output should be:
{
"testpages" : [...data...],
"configs" : [...data...]
}
My code
<script type="text/javascript">
function grabSelected() {
var configs = [];
var testPages = [];
var selectedConfigs = document.getElementByClassName('.testpages').value;
var selectedTestPages = document.getElementByClassName('.configs').value;
for (var i = 0; i < selectedConfigs.length; i++) {
if (selectedConfigs[i].checked) {
configs.push(selectedConfigs[i])
}
}
for (var i = 0; i < selectedTestPages.length; i++) {
if (selectedTestPages[i].checked) {
testPages.push(selectedTestPages[i])
}
}
var jsonString = {"testpages" : testpages, "configs" : configs};
var testJson = JSON.stringify(jsonString);
}
</script>
<body class="wrap">
<form action="POST" >
<div class="testpages" id="left_col">
<input id="tp1" type="checkbox" value="1">Test Page 1<br>
...
...
<input id="tp30" type="checkbox" value="30">Test Page 30<br>
</div>
<div class="configs" id="right_col">
<input id="config_0" type="checkbox" value="Windows XP internet explorer 8">Windows XP
...
...
<input id="config_59" type="checkbox" value="OS X 10.9 Safari 7">OS X 10.9 Safari 7<br>
</div>
</form>
<input id="" type="submit" value="Submit" onclick="grabSelected();" />
</body>
<html>
<script>console.logat the start of the function to see if it's running.return falseon the end.