Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

jhsuZerion commented Oct 17, 2016

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