-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertor.js
More file actions
34 lines (28 loc) · 920 Bytes
/
Copy pathconvertor.js
File metadata and controls
34 lines (28 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function rgbToHex() {
debugger;
var red=document.getElementById('r');
var green=document.getElementById('g');
var blue=document.getElementById('b');
var hexCode =convertNumberToHex(red.value)+convertNumberToHex(green.value)+convertNumberToHex(blue.value);
var elem=document.getElementById('hexval');
hexval.value="#"+hexCode;
ShowColorSample('colorSample', hexCode);
}
function convertNumberToHex(n) {
n = parseInt(n,10);
if (isNaN(n)) return "00";
n = Math.max(0,Math.min(n,255));
return "0123456789ABCDEF".charAt((n-n%16)/16)
+ "0123456789ABCDEF".charAt(n%16);
}
function ShowColorSample(id,sColor) {
var elem;
if (document.getElementById) {
if (elem=document.getElementById(id)) {
if (elem.style) elem.style.backgroundColor="#"+sColor;
}
}
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('btnClick').addEventListener('click', rgbToHex);
});