1
1
I am attempting to write a Greasemonkey script that puts together a refined list of all items that have a check in their checkbox. The list of check boxes can vary from week to week and contains hundreds of items. Looking here I have learned that this can be done by pulling all elements by class name: getElementsByClassName('class_name')
However, I am failing to get the list of elements, let alone grab the values from it.
Here is a simplified version of the site.
<div class="grid_8 pt5 displayInlineTable">
<div id="ListSelector" style="width:450px;float:left; padding-right:10px;">
<div id="testDiv" style="border: solid 1px; overflow: auto; width: 450px;
height: 200px; background-color: white" align="left">
<div id="divLB" class="hstmls" style="width: 600px;">
<input name="Name1" type="checkbox" id="ID1" checked="checked" title="Title1" value="Value1" onclick="tA('thing');">
<label id="ID1_lf" for="ID1">Title1</label>
<br>
<input name="Name2" type="checkbox" id="ID2" checked="checked" title="Title2" value="Value2" onclick="tA('thing');">
<label id="ID2_lf" for="ID2">Title2</label>
<br>
<input name="Name3" type="checkbox" id="ID3" title="Title3" value="Value3" onclick="tA('thing');">
<label id="ID3_lf" for="ID3">Title3</label>
<br>
</div>
</div>
</div>
</div>
I have attempted to play with this on JSFiddle (just see checked values in alert box) but my play code seems to break it.
var checkedValue = null;
var inputElements = document.getElementsByClassName('grid_8 pt5 displayInlineTable');
for (var i = 0; inputElements[i]; ++i) {
if (inputElements[i].checked) {
alert(inputElements[i].value);
}
Ultimately, I plan to take each item that is checked and write it's title into a text box off to the side, each separated by newlines.
Is there a way to determine what check boxes are on the site (within this particular table, as there are many other tables too) and iterate through them, pulling just the title values when applicable?
1This is a perfect example for my needs. Thank you a lot! – JG7 – 2017-08-30T20:00:32.637
I have been using a script that I put together with the beautiful answer that you gave above. However, I could also use the option to list all items that are not checked. Is there an opposite parameter to
input:checked
? – JG7 – 2017-09-05T20:07:43.507You can do that with
input:not(:checked)
. – Brock Adams – 2017-09-05T20:34:01.570So simple. You have literally given me hours back to my life with these answers. – JG7 – 2017-09-06T00:09:42.070
Good to know; glad to help. – Brock Adams – 2017-09-06T00:42:05.780