Skip to content

Instantly share code, notes, and snippets.

@jhsuZerion
Created October 17, 2016 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhsuZerion/c9a51edb6300893085cfb698509ee8e3 to your computer and use it in GitHub Desktop.
Save jhsuZerion/c9a51edb6300893085cfb698509ee8e3 to your computer and use it in GitHub Desktop.
Page-level JavaScript function for working with multi-select elements
/**
* A function to access a value in an option in a multi-select element.
* by converting the value of the multi-select element into a bit and
* @param {integer} i the integer representation from a multi-select element
* @param {position} p the number of the option list value to look-up
* the last option is #1 and increments up
* @return {integer} value of the binary string at the given position
*/
function getValueOfBitPosition(i,p) {
var bit = (i >>> 0).toString(2);
if(p > bit.length) {
return 0;
} else {
bit = bit.split('').reverse().join('');
return Number(bit[p-1]);
}
}
@jhsuZerion
Copy link
Author

Form Package with examples of the function being used as a Dynamic Value and as a Conditional Value
Link to Public Form Package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment