Solved

Appending data to the top line of a text area using javascript

Posted on 2011-03-21
4
323 Views
Last Modified: 2012-05-11
Hi Guys,

thank you for taking the time to look at my question.  Essentially a very simple one I hope.

Essentially I have some text area's, with an onclick event, to add a new line with the time and date, I would like to make this appear at the top of the textarea instead.  

Any assistance would be greatly appreciated.
0
Comment
Question by:mavmanau
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
B34RDY earned 250 total points
ID: 35186226
Here is an attempt that achieves what I believe you want:
<html>
<head>
<title>Textarea Test</title>
<script type="text/javascript">
function addDT(fnArea){
	var d=new Date();
	fnArea.value = d+'\n'+fnArea.value;
}
</script>
</head>
<body>
<textarea id="textArea" cols="25" rows="5" onclick="addDT(this);">This is the text that initially appears in the textarea.</textarea>
</body>
</html>

Open in new window

0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 35186233
try this :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	window.onload = function() {
		var d = new Date();
		d = d.getFullYear() + d2(d.getMonth()) + d2(d.getDate());
		var s = document.getElementById("textareaId").value;
		document.getElementById("textareaId").value = d + "\n" + s;
	}
	function d2(n) { return (n<10)?("0"+n):n; }
</script>
</head>
<body>
<textarea id="textareaId" cols="32" rows="5">12ggf3456sskkflkflks</textarea>
</body>
</html>

Open in new window

0
 

Author Comment

by:mavmanau
ID: 35186244
of course.....I should have thought of that...must be having a worse day than what I thought...lol
0
 

Author Closing Comment

by:mavmanau
ID: 35186424
Thank you for the assist guys!! very much appreciated.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now