FreeTextBox

The no. 1 free ASP.NET HTML Editor.
Welcome to FreeTextBox Sign in | Join | Help
in Search

Cursor Location in Freetextbox.

Last post 11-24-2008, 12:33 PM by CelticWoodworker. 7 replies.
Sort Posts: Previous Next
  •  08-21-2008, 1:48 AM 9385

    Cursor Location in Freetextbox.

    Hi
    I am in need of the professionals on this form. 
    I have a freetextbox,a dropdownlist and a button in my application. when ever user selects a value in dropdownlist and presses button that particular value should be inserted on the cursor location in the freetextbox. if any one have any sample code or any idea as to how to achieve this please reply.
    Thanks
  •  08-21-2008, 7:35 AM 9387 in reply to 9385

    Re: Cursor Location in Freetextbox.

    I think that once you have changed focus to your external dropdownlist, and then to your button, any knowledge of where the cursor was positioned in the FTB will have been lost.  But maybe someone else will prove me wrong.

    I had a similar situation in my app, where I wanted to insert values at a particular location.  What I did was create a custom dropdownlist on the FTB toolbar, and populate it with the value options that the user could choose from.  When they picked an option, the text was automatically pasted to the cursor location.

    Here's an example in my FTB setup,

    Dim MyToolbar As New Toolbar

    Dim MyDDL As New ToolbarDropDownList

    MyDDL.Items.Clear()

    MyDDL.ScriptBlock = "this.ftb.InsertHtml(this.list.options[this.list.options.selectedIndex].value);"

    MyDDL.Title = "Insert Something"

    'Maybe do the following one line in a loop, with data populated from DB?

    MyDDL.Items.Add(New ToolbarListItem("Your Text"))

    MyToolbar.Items.Add(MyDDL)

    MyFTB.Toolbars.Add(MyToolbar)

  •  08-21-2008, 11:01 AM 9388 in reply to 9387

    Re: Cursor Location in Freetextbox.

    Thanks for your reply.
    But I need to insert text on the cursor location in the freetextbox.
    I appreciate your reply. thanks

  •  08-21-2008, 11:13 AM 9389 in reply to 9388

    Re: Cursor Location in Freetextbox.

    Sorry.  Maybe I didn't explain myself very well, but you said you 'need to insert text on the cursor location'.  That's what I just explained how to do, by having the dropdownlist built in to the FTB.  All you have to do is populate the dropdownlist with the text strings that you want to choose from.  When the user selects a text string, it will be inserted at the current position of the cursor.

    If I have missed something obvious here, please let me know, in detail, what is missing from this solution and I will try to help.

     

  •  08-22-2008, 5:07 AM 9393 in reply to 9389

    Re: Cursor Location in Freetextbox.

    Hi

    Thanks a lot.
    I have done same thing with following code, but its not compatible with firefox.

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <%@ Register Assembly="FreeTextBox" Namespace="FreeTextBoxControls" TagPrefix="FTB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script language="javascript" type="text/javascript">

    function insertField(field)
            {
                var EditArea = document.getElementById("txtMessage_htmlEditorArea");
                var TxtArea = document.getElementById("txtMessage");
               
               
                if(document.selection)
                {
                    if(FTB_API['txtMessage'].mode==FTB_MODE_DESIGN)
                    {
                   
                        var DesignView=document.getElementById("txtMessage_designEditor");
                   
                        DesignView.contentWindow.document.body.focus();
                        sel = document.selection.createRange();
                        sel.text = field;//oLst.options[oLst.selectedIndex].value;
                    }
                    else
                    {
                   
                        //var TxtArea = document.getElementById("txtMessage");
                        TxtArea.focus();
                        sel = document.selection.createRange();
                        sel.text = field;// oLst.options[oLst.selectedIndex].value;
                    }
                }
                else if (TxtArea.selectionStart || TxtArea.selectionStart == '0')
                {
                       
                    var startPos = TxtArea.selectionStart;
                    var endPos = TxtArea.selectionEnd;
                    //myField.value = myField.value.substring(0, startPos) + myvl + myField.value.substring(endPos, myField.value.length);
                    TxtArea.value = TxtArea.value.substring(0, startPos) + field + TxtArea.value.substring(endPos, TxtArea.value.length);
                }
           
                  
                else
                {
               
                    TxtArea.value += field;
                }
            }   

        </script>
    </head>
    <body>
        <form name="form1" id="form1" runat="server">
            <br />
            <table>           
                <tr>
                    <td style="width: 100px">
     <select name="ddlPlaceHolders" id="ddlPlaceHolders" style="width:237px;">
        <option value="&lt;Title>">Title</option>
        <option value="&lt;Description>">Description</option>
        <option value="&lt;Date>">Date</option>

    </select> </td>
           <td style="width: 100px">
    <INPUT id="btnInsert" type="button" value="Insert" name="btnInsert" onclick="insertField(document.form1.ddlPlaceHolders.value);"><br/><br/>
    </td>
                </tr>
                <tr>
                    <td style="width: 100px">
        <FTB:FreeTextBox ID="txtMessage" runat="server" Height="300px" Width="500px"></FTB:FreeTextBox>
    </td>
                   
                    <td style="width: 100px">
                    </td>
                </tr>
            </table>
            <br />
            <br />
            &nbsp;
        </form>
    </body>
    </html>
  •  08-22-2008, 5:10 AM 9394 in reply to 9389

    Re: Cursor Location in Freetextbox.

    check out this code its short, simple, and according to my requirement. I got this from http://csharp-online.net/forum/viewtopic.php?p=653#653

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
    <%@ Register Assembly="FreeTextBox" Namespace="FreeTextBoxControls" TagPrefix="FTB" %>


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="formFreeTextBox" runat="server">
        <select name="slcInsert" onchange="FTB_API['FreeTextBox1'].InsertHtml(this.options[this.selectedIndex].text);">
            <option>Text1</option>
            <option>Text2</option>
            <option>Text3</option>
            <option>Text4</option>
            <option>Text5</option>
            <option>Text6</option>
            </select>
            <INPUT id="btnInsert" type="button" value="Insert" name="btnInsert" onclick="FTB_API['FreeTextBox1'].InsertHtml(document.formFreeTextBox.slcInsert.options[document.formFreeTextBox.slcInsert.selectedIndex].text);"><br/><br/>
       
        <FTB:FreeTextBox ID="FreeTextBox1" runat="server" Height="300px" Width="500px"></FTB:FreeTextBox>
       
        </form>
    </body>
    </html>

  •  11-06-2008, 3:08 AM 9561 in reply to 9394

    Re: Cursor Location in Freetextbox.s

    Hi

    I am getting problem in putting text at the cursor location in freetext box which is place in a Place holder and .
    My code is as follows:
      <select name="ddlPlaceHolders" onchange="FTB_API['ctl00_ContentPlaceHolder1_ftbMailText'].InsertHtml
    (ddlPlaceHolders.options[ddlPlaceHolders.selectedIndex].text);">
                     <option value="<!FN>">First Name</option>
            <option Value="<!LN>">Last Name</option>
            <option Value="<!EM>">Email</option>      
            </select>

    the statement
     "FTB_API['ctl00_ContentPlaceHolder1_ftbMailText'].InsertHtml
    (ddlPlaceHolders.options[ddlPlaceHolders.selectedIndex].text);"

    is working fine but when i change it to get value instead of text as "FTB_API['ctl00_ContentPlaceHolder1_ftbMailText'].InsertHtml
    (ddlPlaceHolders.options[ddlPlaceHolders.selectedIndex].text);"

     its not showing any thing in the freetext box. Please help me

    Thanks
    wajans

  •  11-24-2008, 12:33 PM 9596 in reply to 9385

    Re: Cursor Location in Freetextbox.

    I'm using FreeTextbox with vb.net.  When the user saves the page (after typing several lines), it causes a postback; which sets the cursor to the start of the textbox's text. Often the user has typed a lot of text and needs the cursor to remain at the end of the text.  How can I set the cursor to the end of the text? Please advise me.

    Thank you,

    Jim

View as RSS news feed in XML
www.freetextbox.com