Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-12-2004, 01:43 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: May 2004
Location: colombo, sri lanka
Posts: 26
Default JavaScript help.........


Hi guys,

I want to do the following in javascript and would very much appreciate if someone could help me:

I need to know how to obtain the text in a TextArea that I highlight/select with a mouse and then insert this text back into its original position after modifying it.

Thanks a million!!!
__________________
a wise man once said:
\"he who laughs last.........doesn\'t get the joke\".
shehan9999 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 04-12-2004, 12:31 PM   #2 (permalink)
In The Zone
 
Join Date: Aug 2004
Location: ..:::In Beautiful Hearts:::....
Posts: 339
Default Simple

call a function to with dos copy on even onselect Done buddy

u have not made clear what modification u need to make on the text area ?
vijaythefool is offline  
Old 05-12-2004, 03:17 PM   #3 (permalink)
I'm back!
 
Join Date: May 2004
Location: Mumbai, Maharashtra
Posts: 65
Default Tutorial on Manipulating Current Text Selection - by Ravi

Hi Shehan,

Here's a short tutorial for you with a working example to demonstrate exactly what you wanted to do with a <TextArea> element. I have even extended your idea and presented a demo to format any type of text selection anywhere in an HTML document.

Here's the HTML Source of My Example:
#----------[ Start Copying Here ]----------#

<html>
<head>
<title>Tutorial on Manipulating Current Text Selection - by Ravi [Minimalistix]</title>
<!--
Created: Sunday, December 05, 2004, 12:34:11 PM
Modified: Sunday, December 05, 2004, 1:59:21 PM
-->
<script type="text/javascript" language="javascript">
<!--

// -----------------------------------------------------------------+
// The following code demonstrates how to manipulate
// current Text Selection in a <TextArea> element and
// as a Bonus Tip in an HTML document's <Body> too !!
// -----------------------------------------------------------------+
// +---------=:[ by Ravi ]:=---=:[ Minimalistix ]:=---------+
// -----------------------------------------------------------------+

// underline () ;

// This function replaces the current text selection
// in the <TextArea> with the same text but delimited
// with pseudo HTML tags {UNDERLINE} and {/UNDERLINE}
// better known as BBCode (Bulletin Board Code) in BBs.

// These tags can then be either processed client-side using
// scripting languages like javascript or vbscript before the
// form submission or after it on the server-side using ASP,
// PHP, Perl, or Python etc. into the <u> and </u> HTML tags.


function underline ()
{
var selectn = document.selection.createRange () ;
if (selectn != null && selectn.text != "")
selectn.text = "{UNDERLINE}" + selectn.text + "{/UNDERLINE}" ;
}


// boldred () ;

// This function formats the currently selected text
// in the HTML document's body as Bold and Red in color


function boldred ()
{
var selectn = document.selection.createRange () ;
if (selectn != null && selectn.text != "")
{
if (selectn.text.charAt (0) == ' ')
selectn.pasteHTML ("<font style=\"color:#FF0000\">" + selectn.text + "</font>") ;
else
selectn.pasteHTML ("<font style=\"color:#FF0000\">" + selectn.text + "</font>") ;
}
}


//-->
</script>
</head>
<body style="text-align:center">



<textarea style="width:53%;height:20%;">



Girls, it's always better to keep your mouth shut and let ppl think you are a fool than to open it and remove all the doubt.

(Select the above text and press UNDERLINE to see the effect!)
</textarea>



<input type=button value="Underline" onclick="underline();"></input>








<div>
Needing someone is like needing a parachute. If he isn't there the first time you need him, chances are you won't be needing him again.


(Select the above text and press BOLD-RED to see the effect!)
</div>


<input type=button value="Bold-Red" onclick="boldred();"></input>





<div style="color:#006600">
(Please Note: TextArea doesn't have any HTML property associated with it. So, using

BOLD-RED on the "TextArea" will result in an Error. However, you can use UNDERLINE on the "Body" Text.)
</body>
</html>


#----------[ End Copying Here ]----------#

I've tested My Example on Internet Explorer 6.0 SP1.
I hope it helps you and whosoever else is interested in JavaScript.

I've tried to keep My Example as simple as possible but still in case you find any troubles
comprehending my source code you are most welcome with all your queries.

Ravi...
__________________
Little Knowledge is Dangerous but a lot of Ignorance is just as Bad!
Minimalistix is offline  
Old 05-12-2004, 06:06 PM   #4 (permalink)
In The Zone
 
Join Date: Oct 2004
Posts: 437
Default well

may be that code will help
but i think u will have more option if u go to
www.javascript.com
tks
saha
__________________
be who u r :
Saharika is offline  
Old 05-12-2004, 06:34 PM   #5 (permalink)
In The Zone
 
Join Date: Aug 2004
Location: ..:::In Beautiful Hearts:::....
Posts: 339
Default

Well Job are meant for some speacial fool like vj other script dosent work... GALS REALLY HOT
{underline} ie 6 YUP ...





<SCRIPT>

function copyit(theField) {
var selectedText = document.selection;
if (selectedText.type == 'Text') {
var newRange = selectedText.createRange();
theField.focus();
theField.value = newRange.text;
} else {
alert('shehan9999 select a text then press this button');
}
}
// End -->
</script>

</HEAD>


<BODY>

<form name="it">



select text on a web page and copy to text area</p>
<div align="center">
<input onclick="copyit(this.form.select1)" type="button" value="Press to copy the highlighted text" name="btnCopy">



<textarea name="select1" rows="4" cols="45"></textarea>
</div>
</form>



<center>
<font face="arial, helvetica" size"-2">Vijay the fool</font>
</center>

vijaythefool is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by clinton
- by icebags
- by ico
- by gohan89

Advertisement




All times are GMT +5.5. The time now is 11:12 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2