"Grab" Form Field Text Tutorial
Go to
www.cgiscript.net
for more free tools!
Description:
Use these instructions to create a 'grab text' option adjacent to your textarea
within your forms. You can use any of the 3 options, link, button, or image.
See the example in the form below.
Directions:
Use these instructions to create a 'grab text' option adjacent to your textarea
within your forms. You can use any of the 3 options, link, button, or image.
See the example in the form below.
Step 1:
The first thing you need to do is setup
some JavaScript in the HEAD of your HTML document that will do the 'grabbing'.
The function will take whatever form field is passed and set the focus to it
then select the text within it.
<SCRIPT LANGUAGE='JavaScript'>
<!--
function aceGrabText(fieldName){
fieldName.focus();
fieldName.select();
}
-->
</SCRIPT>
Step 2:
The second thing you need to do is setup
the link that will pass the form field data to the JavaScript. It is important
to follow this step carefully. You can see in the example link below the JavaScript
call javascript:aceGrabText(document.form1.field1).
The important part of this call is the "form1" and
the "field1" values. These actually tell the JavaScript what form and field
will be "grabbed". The textarea resides in a form, type the form name in place
of the "form1" name below. Then the textarea itself has a name, type that in
place of the "field1" name.
Note: You can add as many links as
you want, as many forms and textarea fields you have. Simply change the form
name and field name accordingly. They all share the same JavaScript function.
<a href="javascript:aceGrabText(document.form1.field1)">Click
to Select</a>