I have a textbox and set of checkboxes that should link together. value in textbox is the equivalent hex value based on checkbox status.
in HTML side I have checkboxes with ID oc0 to oc19 which each one should control bit 0 to bit 19 of the hex value and vice versa.
what I did, I can get the bit weight based on checkbox ID number (0-19) and I can understand which checkbox should control which bit. But I donnow how to implement this in JS function . here is what I have so far.
this is checkboxes block
<span style="float:left;text-align:left;min-width:70px" for="checkboxSbiCK-oc0">
<input type="checkbox" id="checkboxSbiCK-oc0" data-weight="oc0" class="mdl-checkbox__input checkboxSbiCK">
<label>CK_0</label>
</span>
<span style="float:left;text-align:left;min-width:70px" for="checkboxSbiCK-oc1">
<input type="checkbox" id="checkboxSbiCK-oc1" data-weight="oc1" class="mdl-checkbox__input checkboxSbiCK">
<label>CK_1</label>
</span>
<span style="float:left;text-align:left;min-width:70px" for="checkboxSbiCK-oc2">
<input type="checkbox" id="checkboxSbiCK-oc2" data-weight="oc2" class="mdl-checkbox__input checkboxSbiCK">
<label>CK_2</label>
</span>
..........and same structure till oc19
and this is the textbox that I have:
<label>SBI 20 bit OE Word:</label>
<input type="text" value="0x00000" id="textboxSbiCK" class="guiTextBox" style="width:75px;margin-left: 10px">
and this is the JS function on event of checkbox change
// ----------------------------------------------------------------
// checkbox change event
// ----------------------------------------------------------------
document.querySelectorAll(".checkboxSbiCK").forEach(function(checkboxSbiCK)
{
checkboxSbiCK.addEventListener("change", function(e)
{
var textboxSbiCK = document.getElementById("textboxSbiCK").value;
var checkbox = document.getElementById(this.id);
var outputId = checkbox.id.match((/(checkboxSbiCK-)(.*)$/))[2];
var outputBitNum = outputId.substring(2);//remove oc from the name and just get the output number
var outputBitWeight= 2**outputBitNum; // calculate the weight of the bit based on output number.
//...... to be completed
});
});
I want the value of text box and checkboxes relate to eachother so by changing textbox value, checkboxes' status change, or by changing each checkbox status the hex value gets updated.
checked = 1 unchecked = 0