Biswajit das
Biswajit das

Reputation: 51

display Current date in jsp page

I want to generate current date in a html form and store that in the variable currentDate. when i write it works fine if the user enters in the text area. But I want to store the current date(the user need not put it) and store it in the variable currentDate.

Upvotes: 0

Views: 4561

Answers (1)

sunleo
sunleo

Reputation: 10943

use hidden variable in jsp If it is JSP

JSP HTML:

 <input type="hidden" name="currentDate" id="currentDate" value="<%=new Date()%>">
    <div id="div1"></di>

JAVASCRIPT :

function onLoad()
  {
   document.getElementById('div1').innerHTML ='<%=new Date()%>';
  }

use hidden variable in html If it is HTML , call this onLoad Form

HTML:

<input type="hidden" name="currentDate" value="">
<div id="div1"></di>

JAVASCRIPT :

 function onLoad()
    {
    var month = dateObj.getUTCMonth();
    var day = dateObj.getUTCDate();
    var year = dateObj.getUTCFullYear();

    newdate = year + "/" + month + "/" + day;
    document.getElementById('currentDate').value=newdate;
    document.getElementById('div1').innerHTML =newdate;
    }

Upvotes: 2

Related Questions