codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  send textarea name as a variable to function  rosha at 13:06 on Sunday, May 15, 2005
 

I have a js function that make selected portion of text in a textarea bold.
and I have 2 textareas named 'frst' and 'scnd' consequently and I have one button called 'Make it Bold' which calls my above function to formate the text selected in textarea "frst" as bold text.

To call my function I need to send the textarea name (which i want its text to be formatted as the following: (Notice I send the name of the first textarea which is 'frst')

input name="Button" type="button" onclick="fBold(this.form.frst;" value="Make it Bold"/


My problem is that I want to send the textarea name as a variable instead of sending a specific texatrae name as I have 2 and some times more than 2 textarea on same page, thus I want the name of the textarea which has cursor focused on it to be dynamically sent when pressing the 'Make it bold' button

Summary: I need to know the name of the textarea which currently has the cursor set inside and then send this name to the button of 'Make it bold' which then will call my function that makes text bold.
i.e I want it look like:

<input name="Button" type="button" onclick="fBold(this.form.TEXTAREA NAME;" value="Make it Bold"/>

where TEXTAREA NAME is the name of the textarea which currently has cursor set on.

My code is :

<script type="text/javascript">

// the 'storeCaret' function is concerned with knowing the postion the cursor is currently standing at

function storeCaret (textEl) {
if (textEl.createTextRange)
textEl.caretPos = document.selection.createRange().duplicate();

}


// the fbold is concerned with giving effects to the text


function fBold (textEl)
{

var range=document.selection.createRange();
if (textEl.createTextRange && textEl.caretPos)
{
var caretPos = textEl.caretPos;
caretPos.text =
caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
text + ' ' : ("<b>"+range.text+"</b>");
}
}

</script>
<textarea name = 'frst'
onselect="storeCaret(this);"
onclick="storeCaret(this);"
onkeyup="storeCaret(this);"
ondblclick="storeCaret(this);"
>This is first textarea</textarea>

<input name="button" type="button" onclick="fBold(this.form.frst);" value="Make it Bold"/>

I hope I have explained my self well
Thanks for you help








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  java programming help
•  java programming help
•  Re: hi there! first post
•  Reference a <TABLE> HTML Cell in VBA
•  Re: datagrid linkbutton will not fire Postback at random times
•  Re: Running a Javascript from VBA.
•  Re: how to extract search engine results
•  Re: APIs to convert file format
•  Re: Best collection type for this project?


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005