javascript - Jquery: How to show date with textbox value? -
i newbie in jquery , wrote below code
<h1>type comment below </h1> <h2>textbox value : <label id="msg"></label>-<label id="date"></label></h2> <div style="padding:16px;"> textbox : <input type="text" value="" placeholder="type comment"></input> </div> <button id="get">get textbox value</button>
var fulldate = new date(); $("button").click(function(){ $('#msg').html($('input:text').val()); });
how display date when submit button press label have id="date"
? when user press submit button want display
"user entered textbox value - date time"
just use proper css selectors add messages , date. refer code below :
$("button").click(function() { var msg = $('input:text').val(); var fulldate = new date(); $('#msg').html(msg); $('#date').html(tolocal(fulldate)); }); function tojsonlocal (date) { var local = new date(date); local.setminutes(date.getminutes() - date.gettimezoneoffset()); return local.tojson().slice(0, 10); } function tolocal (date) { var local = new date(date); local.setminutes(date.getminutes() - date.gettimezoneoffset()); return local.tojson().replace('t', ' ').slice(0, 19); }
note: tojsonlocal, tolocal used format date.
jsfiddle : https://jsfiddle.net/nikdtu/q8zmlebz/
Comments
Post a Comment