/    Sign up×
Community /Pin to ProfileBookmark

Insert timestamp into textarea

I am using the following code to insert a time stamp into a text area. My Problem is it removes any data in the text area. I want it to add the time stamp at the end of the data without removing any of the data.
Can anybody help me with this?

<script language=”JavaScript”>
function setStartTimeNow()
{
var d = new Date();
var currYear = d.getFullYear();
var currMonth = d.getMonth() + 1;
var currDate = d.getDate();
var currHour = d.getHours();
var currMin = d.getMinutes();
time = currYear + “-” +
(currMonth < 10 ? “0” : “”) + currMonth + “-” +
(currDate < 10 ? “0” : “”) + currDate + ” ” +
(currHour < 10 ? “0” : “”) + currHour + “:” +
(currMin < 10 ? “0” : “”) + currMin;

theInput = document.getElementById(“startWhen”);
theInput.value = time;
}
</script>
<form>
<textarea cols=”” rows=”” name=”note” id=”startWhen”>keep this data</textarea>

<a onclick=”setStartTimeNow()”>Set timestamp</a>
</form>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangFeb 04.2007 — Concatenate: [I]theInput.value [B][COLOR="SeaGreen"]+[/COLOR][/B]= time;[/I]
Copy linkTweet thisAlerts:
@rkurthauthorFeb 04.2007 — could you show me what you mean. I don't understand where I would put

theInput.value += time;
Copy linkTweet thisAlerts:
@FangFeb 04.2007 — At the end of the function:function setStartTimeNow()
{
var d = new Date();
var currYear = d.getFullYear();
var currMonth = d.getMonth() + 1;
var currDate = d.getDate();
var currHour = d.getHours();
var currMin = d.getMinutes();
time = currYear + "-" +
(currMonth &lt; 10 ? "0" : "") + currMonth + "-" +
(currDate &lt; 10 ? "0" : "") + currDate + " " +
(currHour &lt; 10 ? "0" : "") + currHour + ":" +
(currMin &lt; 10 ? "0" : "") + currMin;

theInput = document.getElementById("startWhen");
[COLOR="SeaGreen"]theInput.value += time;[/COLOR]
}
Copy linkTweet thisAlerts:
@rkurthauthorFeb 04.2007 — Thanks
×

Success!

Help @rkurth spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...