Created
October 17, 2016 18:43
-
-
Save jhsuZerion/c9a51edb6300893085cfb698509ee8e3 to your computer and use it in GitHub Desktop.
Page-level JavaScript function for working with multi-select elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Form Package with examples of the function being used as a Dynamic Value and as a Conditional Value
Link to Public Form Package