-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (32 loc) · 1.15 KB
/
script.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
/*window.onload = () => {
insertNum();
document.getElementById('label').addEventListener('click', insertNum)
}*/
document.getElementById('btn').onclick = insertNum;
document.getElementById('label').onclick = insertNum;
function insertNum() {
do {
var non_valido = true;
var numero = prompt('Insert number');
if (numero == null)
non_valido = false;
else
if (!isNaN(numero) && numero.trim() != '') {
non_valido = false;
numero = numero.trim().replace('+', '');
var prefisso = numero.substring(0, 2)
numero = numero.substring(2)
document.getElementById('label').innerHTML = '+' + prefisso + ' ' + numero;
var phone = prefisso + numero;
}
else
alert('Not valid');
} while (non_valido)
if (numero != null) {
document.getElementById('btn').onclick = function () {
var msg = document.getElementById('msg').value;
msg = encodeURI(msg)
window.open('https://api.whatsapp.com/send?phone=' + phone + '&text=' + msg)
}
}
}