-
Notifications
You must be signed in to change notification settings - Fork 1
/
phonenumber.js
76 lines (54 loc) · 1.87 KB
/
phonenumber.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//Selecting individual Numbers
var digit2english_dict = 'zero,one,two,three,four,five,six,seven,eight,nine'.split(',');
var phonenumberform,
digit_selects = [];
function genZeroToN(n) {
return Array.apply(null, {length: Number(n)}).map(Number.call, Number);
}
String.prototype.replaceAt = function(index, character) {
return this.substr(0, index) + character + this.substr(index+character.length);
}
function digit2english(value) {
return digit2english_dict[Number(value)];
}
function createDigitOption(value) {
var option = document.createElement("option");
option.value = value;
option.innerHTML = digit2english(value);
return option;
}
function updateResultDigit(pos, val, elm) {
elm.value = elm.value.replaceAt(pos, val);
}
function onFormChange(ev) {
updateResultDigit(Number(ev.target.name.replace(/^digit/,''))-1, ev.target.selectedOptions[0].value, ev.target.parentElement.result)
}
function pageLoad(ev) {
var cache_zero2ten = genZeroToN(10);
var pnform_elements = (phonenumberform = document.getElementById("phonenumberform")).elements;
cache_zero2ten.map(function(i){
cache_zero2ten.map(function(j){
pnform_elements["digit"+(i+1)].appendChild(createDigitOption(j));
});
});
phonenumberform.result.value = new Array(10).fill(0).join('');
phonenumberform.addEventListener('change', onFormChange, false);
}
window.addEventListener('load', pageLoad, false);
//Right to left <vigzmv>
function rtl(element){
if(element.setSelectionRange){
element.setSelectionRange(0,0);
}
}
function satans666(ev){
inputval = document.getElementById("rtlinput");
len = inputval.value.length;
len = (Math.pow(10,len)-1)/9*6;
inputval.value = len;
ev.preventDefault();
}
function pageLoad2(ev) {
document.getElementById("rtlsubmit").addEventListener("click", satans666, false);
}
window.addEventListener('load', pageLoad2, false);