Skip to content

Instantly share code, notes, and snippets.

@jamestoyer
Created August 29, 2013 17:18
Show Gist options
  • Save jamestoyer/6380871 to your computer and use it in GitHub Desktop.
Save jamestoyer/6380871 to your computer and use it in GitHub Desktop.
$(function () {
$('#update-sf-id').click(function () {
var answer = prompt(
"Enter a 15 character Salesforce ID",
$('#SalesForceID').val().substr(0, 15)
);
if (answer == '' || answer == null) {
alert("Please enter a Salesforce ID");
} else if (answer.length != 15) {
alert("Salesforce ID's can only be 15 characters long");
} else if (answer != null && answer.length == 15) {
$('#SalesForceID').val(function () {
var chunks = new Array();
chunks[0] = answer.substr(0, 5);
chunks[1] = answer.substr(5, 5);
chunks[2] = answer.substr(10, 5);
var bits = 0;
var extra = '';
for (i in chunks) {
var chunk = chunks[i];
bits = 0;
for (j in chunk) {
if (chunk[j] < = 'Z' && chunk[j] >= 'A') {
bits += Math.pow(2, j);
};
}
if (bits < 26) {
extra += String.fromCharCode('A'.charCodeAt(0) + bits);
} else {
extra += String.fromCharCode('0'.charCodeAt(0) + (bits - 26));
}
};
return answer + extra;
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment