1. Hey Guest Did you know you can win an Honor 10 phone worth ₹33,000 and an additional ₹70,000 in paytm vouchers, just by replying to some threads and taking part in the discussions happening in the Honor Hub?

    What are you waiting for? Start commenting and start winning! Remember to read the instructions posted here.

    Dismiss Notice

JavaScript help.........

Discussion in 'QnA (read only)' started by shehan9999, Dec 3, 2004.

Thread Status:
Not open for further replies.
  1. shehan9999

    shehan9999 New Member

    Joined:
    May 26, 2004
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    colombo, sri lanka
    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!!! :D
     
  2. vijaythefool

    vijaythefool New Member

    Joined:
    Aug 18, 2004
    Messages:
    339
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    ..:::In Beautiful Hearts:::....
    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 ?
     
  3. Minimalistix

    Minimalistix I'm back!

    Joined:
    May 16, 2004
    Messages:
    65
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Mumbai, Maharashtra
    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...
     
  4. Saharika

    Saharika New Member

    Joined:
    Oct 18, 2004
    Messages:
    437
    Likes Received:
    0
    Trophy Points:
    0
    well

    may be that code will help
    but i think u will have more option if u go to
    www.javascript.com
    tks
    saha
     
  5. vijaythefool

    vijaythefool New Member

    Joined:
    Aug 18, 2004
    Messages:
    339
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    ..:::In Beautiful Hearts:::....
    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>
     
Thread Status:
Not open for further replies.

Share This Page