Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. How to put clipboard data into TextBox

How to put clipboard data into TextBox

Scheduled Pinned Locked Moved JavaScript
helptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ravindra Bisen
    wrote on last edited by
    #1

    Hi , I have a string into clipboard (FirstName MiddleName Last Name). i want to paste this data into three different Textbox by a single paste in First Textbox. ex . if i paste "Ravi Shankar Sharma" then the data should appear like this First Text box : Ravi Second Text Box: Shankar Third text box : Sharma any one can help me

    J R 2 Replies Last reply
    0
    • R Ravindra Bisen

      Hi , I have a string into clipboard (FirstName MiddleName Last Name). i want to paste this data into three different Textbox by a single paste in First Textbox. ex . if i paste "Ravi Shankar Sharma" then the data should appear like this First Text box : Ravi Second Text Box: Shankar Third text box : Sharma any one can help me

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      jQuery solution is pretty simples, but there is one weirdness, you cant read the value of the field until after it's been pasted, so I intoduce a short 1ms delay between paste, and trying to update the field:

      $('#first').on('paste',function(e){

      setTimeout(function(){
      var text = $('#first').val().split(' ');
      $('#first').val(text[0]);
      $('#second').val(text[1]);
      $('#third').val(text[2]);
      },1)
      });

      Live example: http://jsfiddle.net/PjT28/[^] I also don;t cover any of the multitude of error conditions (empty paste, paste without 3 names separated by a single space etc etc etc)

      1 Reply Last reply
      0
      • R Ravindra Bisen

        Hi , I have a string into clipboard (FirstName MiddleName Last Name). i want to paste this data into three different Textbox by a single paste in First Textbox. ex . if i paste "Ravi Shankar Sharma" then the data should appear like this First Text box : Ravi Second Text Box: Shankar Third text box : Sharma any one can help me

        R Offline
        R Offline
        Ravindra Bisen
        wrote on last edited by
        #3

        <html>
        <head>
        <title>Java Script - Capita Learning : ClipBoard Data </title>

        <script type="text/javascript" >

        function afterPaste(txt)
        {
          var T = window.clipboardData.getData('Text');
          document.getElementById('Txt\_Data2').value = T;
          document.getElementById("Txt\_Data3").value = T;
           var len = T.length;
           var n = T.indexOf(" ");
            document.getElementById("Txt\_Data2").value = T.substring(0,n);
            T = T.substring(n+1,len);
            len = T.length;
        n = T.indexOf(" ");
            document.getElementById("Txt\_Data3").value = T.substring(0,n);
        document.getElementById("Txt\_Data4").value = T.substring(n+1,len);
        
        }
        

        </script>
        </Head>
        <body>
        <p> On Paste event in java script
        <p> <Input Type="Textbox" ID="Txt_Data" OnPaste="afterPaste(this.value)" >
        <p> <Input Type="Textbox" ID="Txt_Data2" Name="Txt_Data2" >
        <p> <Input Type="Textbox" ID="Txt_Data3" Name="Txt_Data3" >
        <p> <Input Type="Textbox" ID="Txt_Data4" Name="Txt_Data4" >

        </body>
        </html>

        I 1 Reply Last reply
        0
        • R Ravindra Bisen

          <html>
          <head>
          <title>Java Script - Capita Learning : ClipBoard Data </title>

          <script type="text/javascript" >

          function afterPaste(txt)
          {
            var T = window.clipboardData.getData('Text');
            document.getElementById('Txt\_Data2').value = T;
            document.getElementById("Txt\_Data3").value = T;
             var len = T.length;
             var n = T.indexOf(" ");
              document.getElementById("Txt\_Data2").value = T.substring(0,n);
              T = T.substring(n+1,len);
              len = T.length;
          n = T.indexOf(" ");
              document.getElementById("Txt\_Data3").value = T.substring(0,n);
          document.getElementById("Txt\_Data4").value = T.substring(n+1,len);
          
          }
          

          </script>
          </Head>
          <body>
          <p> On Paste event in java script
          <p> <Input Type="Textbox" ID="Txt_Data" OnPaste="afterPaste(this.value)" >
          <p> <Input Type="Textbox" ID="Txt_Data2" Name="Txt_Data2" >
          <p> <Input Type="Textbox" ID="Txt_Data3" Name="Txt_Data3" >
          <p> <Input Type="Textbox" ID="Txt_Data4" Name="Txt_Data4" >

          </body>
          </html>

          I Offline
          I Offline
          itzzmearun
          wrote on last edited by
          #4

          hi, I think this will work only in ie.what we can do for other browsers?

          D 1 Reply Last reply
          0
          • I itzzmearun

            hi, I think this will work only in ie.what we can do for other browsers?

            D Offline
            D Offline
            DaveAuld
            wrote on last edited by
            #5

            You could try putting Google Search to use........I am sure you could probably find something relevant in the time it took you to post that message.

            Dave Find Me On: Web|Facebook|Twitter|LinkedIn


            Folding Stats: Team CodeProject

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups