Lazy Script

in Code no responses

I was playing around with JavaScript and came across this script that allows the user to add predefined data to a forms’ textarea with a click of a mouse. An example of where this could be used is  if code needed to quickly be added to a textarea (usually because of laziness ;P)

Here’s the code:

Put this in the head of your document:

<script language="JavaScript" type="text/JavaScript">
function AddItem(ItemId)
{
document.Form.textarea.value = document.Form.textarea.value + ItemId;
}
</script>

This is the form:

<form name="Form" method="post" action="post.php">
<a href="#" onclick="AddItem('<em></em>');"> Italic</a>
<textarea rows="10" name="textarea" cols="70"></textarea> <br /><br />
</form>

How it works.

The mechanics of the script are simple. When the onclick="AddItem();" function is called the contents between the brackets of the onclick event is added to the textarea defined textarea. In this case the name of the textarea is ‘textarea’ and the name of the form is ‘Form’ so that’s what was changed in the script.

 
comments

No Comments Yet

 

Have something to say?