0

Any help guys How to get century of date wich inserted by user from input exam ( 01.06.1988) by array JavaScript

<!DOCTYPE html> <html> <body> <p>Click the button to display century of a given date exam 01.06.1988.</p> <input id="sara"/> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var dam = []; dam.push(parseInt(document.getElementById("sara").value); if(dam[8]==9){ document.getElementById("demo").innerHTML = "20"; }else if(dam[7]==2 ){ document.getElementById("demo").innerHTML ="21" ; } } </script> </body> </html>

3rd Jul 2020, 10:14 AM
Sabah RK
Sabah RK - avatar
2 Respuestas
0
Haven't checked it with various possibilities, but this may be what you wanted. function myFunction() { var raw = document.getElementById("sara").value; if(raw.length === 10 && raw.indexOf(".") !== -1) { raw = raw.split("."); if(raw.length === 3 && raw[2].length === 4) { var year = parseInt(raw[2]); if(year !== NaN) { document.getElementById("demo").innerHTML = (parseInt(year / 100) + 1); return false; } } } document.getElementById("demo").innerHTML = ""; }
3rd Jul 2020, 11:18 AM
Ipang
0
how to get the century from the inserted date by user ?
3rd Jul 2020, 1:46 PM
Sabah RK
Sabah RK - avatar