Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  190] [ 2]  / answers: 1 / hits: 44559  / 10 Years ago, sat, december 27, 2014, 12:00:00
<html>
<body>
Date: <input type=text id=txt placeholder= />
</body>
</html>


What should i specify inside placehoder quotes so that i can view current date in my textbox


More From » jquery

 Answers
12

These are one of the soultions how to display current date in textbox:



1. JAVASCRIPT SOLUTION



<!DOCTYPE html>
<html>
<body onload=myFunction()>


Date: <input type=text id=demo/>

<script>
function myFunction() {
document.getElementById('demo').value= Date();
}
</script>
</body>
</html>


EDIT



Instead of value, in the same way by id, you could set the placeholder as you wish:



document.getElementById('demo').placeholder= Date();





2. JQUERY SOLUTION



<!DOCTYPE html>
<html>
<head>
<script src=http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js></script>
</head>
<body onload=myFunction()>


Date: <input type=text id=demo/>

<script>
function myFunction() {

$(document).ready(function(){
$('#demo').attr(placeholder, Date());
});

}
</script>
</body>
</html>


I think this will help you.


[#68372] Wednesday, December 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
victorr

Total Points: 193
Total Questions: 86
Total Answers: 105

Location: Pitcairn Islands
Member since Thu, Jun 24, 2021
3 Years ago
victorr questions
Fri, Nov 13, 20, 00:00, 4 Years ago
Sat, Jul 25, 20, 00:00, 4 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
;