Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
edit .asp files 5 31
Help in good tutorials for PHP, HTML and CSS 6 41
removing a class in javascript 4 50
Implement a function similar to grep in vanilla Javascript 3 21
Find out what you should include to make the best professional email signature for your organization.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

829 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