Solved

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

Posted on 2011-03-21
4
338 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

831 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