javascript - how can I collect form input in date format and display it on page -
i trying take form input of type date , display on page. nothing being displayed when
function checkin(){ var date = document.getelementbyid("cindate").value; var datearray = date.split("/");<!-- puts date datearray-> var s = document.getelementbyid("datei"); s.textcontent = datearray[1]"th of july";<!-- shows 2nd index of datearray on page-> }
<form id="myform"> <!-- collects checkin date form input --> check in date: <input type="date" name="checkin" id="cindate"> <button onclick="checkin()" >submit</button> </form> <h1 class="al">hotel room availability</h1> <p class="al">you want check in on <span id="datei"></span> <!-- shows checkin date --> </p>
for solve problem can use code source :
<!doctype html> <html> <body> <h1>javascript can validate input</h1> <p>please input date template: 17/06/1982</p> <input id="cindate"> <button type="button" onclick="myfunction()">submit</button> <p id="datei"></p> <script> function myfunction() { var date = document.getelementbyid("cindate").value; var datearray = date.split("/"); var s = document.getelementbyid("datei"); s.textcontent = datearray[1]+"th of july"; } </script> </body> </html>
Comments
Post a Comment