Go to DotNetFunda.com
 Online : 5300 |  Welcome, Guest!   Login
 
Home > Articles > JavaScript > Finding Curosr Position Using JavaScript and Drag and Drop from WebControls

Submit Article | Articles Home | Search Articles |

Finding Curosr Position Using JavaScript and Drag and Drop from WebControls

 Posted on: 2/24/2009 10:24:45 PM by Majith | Views: 2594 | Category: JavaScript | Level: Advance | Print Article
I am going to explain about javascript code for Drag from ASP.Net ListBox and to Drop in the specific Cursor location of TextArea .

.NET Training Videos!
Buy online comprehensive training video pack just for $35.00 only, see what's inside it.

Finding Curosr Position Using JavaScript and Drag and Drop Values
Introduction:

I am going to explain about javascript code for Drag  from ASP.Net ListBox and to Drop in the specific Cursor location of TextArea .

Solution:

A ListBox having some Parameters or values which refers the corresponding database records.We have to  Drag the valuesfrom ListBox  and  Drop in the  TextArea . In Text area we have to find the cursor position and Drop the Values from ListBox. 


ASPX Code:

    Email Message:
  <asp:TextBox ID="txtMsg" runat="server" TextMode="MultiLine" Rows="10" Columns="50"   onclick="storeCur(this);" onkeyup="storeCur(this);" onselect="storeCur(this);"></asp:TextBox>
                              
 List Values:
<asp:ListBox ID="lstParameter" runat="server"    DataTextField="db_Values" DataValueField="db_Names" onmousedown="d = new drag(this)"
onmouseup="d.drop(this.form.txtMsg)" onmouseout="if (typeof d != 'undefined') d.setIndex()"> </asp:ListBox>

JavaScript Code:

 <script language="javascript" type="text/javascript">
               function storeCur(txtMsg)
               {
                   if (txtMsg.createTextRange)
                     txtMsg.caretPos = document.selection.createRange().duplicate();
               }
                function drag(objSource)
                {
               this.select = objSource;
             }
                function drag.prototype.drop(objDest)
                {
                if (!this.dragStart) return;
                this.dest = objDest;
      var pt=this.option.cloneNode(true);
                   if (objDest.createTextRange && objDest.caretPos)
                     {                            
                               var caretPos = objDest.caretPos;
                               if(caretPos.text.charAt(caretPos.text.length - 1) == '')
                               {                                  
                                    caretPos.text =  pt.value;
                               }                
                  }
        function drag.prototype.setIndex()
        {
         var i = this.select.selectedIndex;
         window.status="selectedIndex = "+i;
         if (i==-1) return;
         this.option = this.select.options[i];
         this.dragStart=true;
        }
   if (myField.selectionStart || myField.selectionStart == ‘0')
    {
       var startPos = myField.selectionStart;
       var endPos = myField.selectionEnd;
      myField.value = myField.value.substring(0, startPos)+ myValue
    + myField.value.substring(endPos, myField.value.length);
    }
  else
   {
   myField.value += myValue;
   }
   }      
    </script>
Conclusion
Finally we find out the solution for Drag and Drop from Webcontrols and Locating the Cursor position.


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Interesting?   Share and Bookmark this kick it on DotNetKicks.com


About Majith Basha

Experience:0 year(s)
Home page:
Member since:Friday, July 18, 2008
Level:Starter
Status: [Member]
Biography:
 Latest post(s) from Majith

   ◘ Checking Existing Records Using Array of Data Rows posted on 4/13/2009 5:41:54 AM
   ◘ Finding Curosr Position Using JavaScript and Drag and Drop from WebControls posted on 2/24/2009 10:24:45 PM
   ◘ Reading Selected Element from XML using ASP.NET, C# posted on 11/25/2008 8:23:38 AM
   ◘ Java Script GridView ClientSide Validation posted on 9/30/2008 12:22:12 AM
   ◘ Diff Between DataGrid and GridView posted on 9/17/2008 11:20:35 PM


Submit Article

About Us | The Team | Advertise | Contact Us | Feedback | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found copied contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
All rights reserved to DotNetFunda.Com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
(Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher)