[Javascript] Click on link to generate text in a textarea?

David Yee dyee at AMSResponse.com
Fri Dec 21 14:12:51 CST 2001


Thanks Peter- I'll give it a shot!

David

> -----Original Message-----
> From: Peter Brunone [mailto:peter at brunone.com]
> Sent: Friday, December 21, 2001 12:24 PM
> To: javascript at LaTech.edu
> Subject: Re: [Javascript] Click on link to generate text in a 
> textarea?
> 
> 
> 
>     Perhaps you could use the onFocus() event handler to send 
> a textbox's
> name to a hidden form field and then use the eval() function 
> to dynamically
> build the name of the correct box.  The only problem you 
> might have is that
> I'm not sure whether or not the onFocus event is triggered 
> for everything
> (i.e. tabbing into the field).  I guess some experimentation 
> is in order.
> 
> <TEXTAREA NAME="text1"
> onFocus="document.mainForm.hiddenField.value='text1';"
> 
> <SCRIPT LANGUAGE="JavaScript">
> function writeText(newText) {
>     var boxName = eval("document.mainForm." +
> document.mainForm.hiddenField.value);
>      // Build the reference to the text box
>      var myBox = eval("document.mainForm." + boxName);
>      // Concatenate the new text to the end of the current text
>      // (The /n is a carriage return)
>      myBox.value = myBox.value + "\n" + newText;
>      }
>  </SCRIPT>
> 
> 
> ----- Original Message -----
> From: "David Yee" <dyee at AMSResponse.com>
> To: <javascript at LaTech.edu>
> Sent: Friday, December 21, 2001 2:03 PM
> Subject: RE: [Javascript] Click on link to generate text in a 
> textarea?
> 
> 
> | Thanks again Peter- I do have another related question, 
> however.  Is it
> | possible to generate that text in whichever text box that 
> has the current
> | cursor in it?  So in this instance the code would have to 
> know what the
> name
> | of the current text box is.
> |
> | David
> |
> | > -----Original Message-----
> | > From: Peter Brunone [mailto:peter at brunone.com]
> | > Sent: Tuesday, December 18, 2001 12:33 PM
> | > To: javascript at LaTech.edu
> | > Subject: Re: [Javascript] Click on link to generate text in a
> | > textarea?
> | >
> | >
> | > <FORM NAME="mainForm">
> | >
> | > ...
> | >
> | > <A HREF="javascript:writeText('text1','Extra 
> text')">Click this</A>
> | > <TEXTAREA NAME="text1">Here's some text</TEXTAREA>
> | >
> | > ...
> | >
> | > </FORM>
> | >
> | > <SCRIPT LANGUAGE="JavaScript">
> | > function writeText(boxName, newText) {
> | >     // Build the reference to the text box
> | >     var myBox = eval("document.mainForm." + boxName);
> | >     // Concatenate the new text to the end of the current text
> | >     // (The /n is a carriage return)
> | >     myBox.value = myBox.value + "\n" + newText;
> | >     }
> | > </SCRIPT>
> | >
> | > Cheers,
> | >
> | > Peter
> | >
> | > ----- Original Message -----
> | > From: "David Yee" <dyee at AMSResponse.com>
> | > To: <javascript at LaTech.edu>
> | > Sent: Tuesday, December 18, 2001 2:09 PM
> | > Subject: [Javascript] Click on link to generate text in a 
> textarea?
> | >
> | >
> | > | Hi all.  Is it possible to write javascript that'll 
> automatically
> | > | type in text in a <textarea> when you click on the link?
> | > E.g. I have
> | > | a link called COMPANY_NAME, and when I click on the 
> link I want the
> | > | text "My Company" to be typed in immediately into the
> | > <textarea> box
> | > | next to that link at the cursor (thus not destroying 
> what's already
> | > | in the text box).  Thanks for any help!
> | > |
> | > | David
> | > | _______________________________________________
> | > | Javascript mailing list
> | > | Javascript at LaTech.edu
> | > | https://lists.LaTech.edu/mailman/listinfo/javascript
> | > |
> | >
> | > _______________________________________________
> | > Javascript mailing list
> | > Javascript at LaTech.edu
> | > https://lists.LaTech.edu/mailman/listinfo/javascript
> | >
> | _______________________________________________
> | Javascript mailing list
> | Javascript at LaTech.edu
> | https://lists.LaTech.edu/mailman/listinfo/javascript
> |
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 



More information about the Javascript mailing list