html - displaying current date in a text box - javascript -


i having great difficulty getting current date inputted text box within form creating default value. @ moment have following code, believe creates current date, followed text box code unsure on how modify in order date displayed inside.

function getdate(){  var todaydate = new date();  var day = todaydate.getdate();  var month = todaydate.getmonth() + 1;  var year = todaydate.getfullyear();  var datestring = day + "/" + month + "/" + year;  document.getelementbyid("frmdate").value = datestring(); }  <input type="text" name="frmdatereg" required id="frmdate"  value="getdate()"> 

if suggest how create todays date , input textbox default appreciated. (please excuse format issues new stack overflow) thanks

you've got right idea. it's out of order:

<input type="text" name="frmdatereg" required id="frmdate" value="">  function getdate(){    var todaydate = new date();    var day = todaydate.getdate();    var month = todaydate.getmonth() + 1;    var year = todaydate.getfullyear();    var datestring = day + "/" + month + "/" + year;    document.getelementbyid("frmdate").value = datestring;   }  getdate();  

your code correct, except adding function call in value doesn't anything. need else trigger function. way have there, execute automatically when page loads.

aslo, datestring not function. it's variable. can leave off ()


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -