I've got a javascript function which takes the text a user has selected on one DIV or P region and copies the selected text to a TEXTAREA. I'm using jquery and my function runs on the mouseup event.

$("#my_element").mouseup(function() {
  // blah blah blah
});

This does not work on an iPad or iPod Touch and I'm assuming it doesn't work on other touch-screen devices but have not tested it. Do these machines fire some other event besides mouseup that I might use for this purpose?

Any help would be much appreciated.

    Thanks for that. Definitely helpful info, but I'm still wondering a couple of things:
    1) do touch end and touchstart get triggered when you are working with a selection? Or is there some other event connected to text selection?
    2) is the event the same for an android tablet?

    Hopefully we'll get some answers here shortly. In the meantime, I'll be looking around for info.

      This would be a lot easier if I had an iPad, BTW.

        Ahhh the simulator. I suppose this means I'll have to find somewhere to set up my Mac. Thanks for that BG.

          sneakyimp;10993768 wrote:

          I suppose this means I'll have to find somewhere to set up my Mac.

          That might be the most beneficial in that the iOS tools are probably more native/mature on the Apple OS, but you can also do a search for a phrase like iOS simulator for windows and get a few results that look relevant.

          Can't vouch for that route, though, as I've never done a single bit of iOS development (or any mobile-conscious development, for that matter). Good luck! :p

            bradgrafelman;10993769 wrote:

            but you can also do a search for a phrase like iOS simulator for windows and get a few results that look relevant.

            Thanks for that tip also. I expect I'll try to use the official items.

            bradgrafelman;10993769 wrote:

            Can't vouch for that route, though, as I've never done a single bit of iOS development (or any mobile-conscious development, for that matter). Good luck! :p

            You may find the trajectory of the graph here interesting.

              sneakyimp;10993776 wrote:

              You may find the trajectory of the graph here interesting.

              Eh, it's fun to look at just to get an idea of what the bigger picture looks like, but unfortunately it's far from relevant to the type of programming I do nowadays which is mostly embedded C, Python, dabs of assembly here and there, ... nothing as fun as PHP/SQL/HTML/CSS/JS, in other words. :p

                Assembler? No way! I had to do some of that in college and found it kind of fascinating because the hardware topology was so apparent. E.g., "move memory contents from address 0xDEADBEEF to register 2". Just implementing a for loop was a total pain, but it give one a power trip to contemplate the speed possible when dealing directly with the hardware without any bytecode or virtual machines or other intermediary abstractions to siphon off instruction cycles.

                So now I'm wondering how you find time to graciously post on here so much. If you are feeling generous, perhaps you might at some point provide some suggestions to help me understand the use of php_add_var_hash in the context of serialization in the PHP source code. Johannes Schluter suggested I use it in response to a question I posted to the PECL dev list. The basic idea is that, as new steward of AMFEXT, I'm implementing AMF3 serialization and must deal with data structures that might be recursively self-referential.

                In the meantime, I'm going to try and see if I can figure out this selection issue and report the results here.

                  OK so I've got some news but it's mostly dreary. I have an iPhone simulator from an old SDK but it doesn't seem to support any kind of selection behavior. In order to get the "iOS Simulator" which apparently does iPad mode, I have to upgrade to Lion and to upgrade to Lion I have to first upgrade to Snow Leopard so I'm looking at about $70 in software upgrades for a computer I use to watch neftlix 🙁

                  The other dreary bit is that I've been searching around for touch-related event handling information and I can't seem to locate any that will reliably let me fire an event when the selection changes. When one holds a finger down on a DIV or P tag in my iPod Touch, a sort of selection mode is enabled but when I attempt to alter the selection start and end point, I don't seem to get more touchend events firing despite the fact I am touching the screen and altering the start/end points of my selection. I have so far tried the touchend event and will try touchmove in a bit. Some sample code:

                  <html>
                  <head>
                  <script type="text/javascript">
                  document.addEventListener('DOMContentLoaded', function() {
                    document.addEventListener('touchend', function(evt) {
                  
                  var el = document.getElementById("log");
                  if (!el) {
                    alert('no log element');
                  }
                  el.innerHTML += log(evt);
                  
                  var t = '';
                  if(window.getSelection){
                    t = window.getSelection();
                  }else if(document.getSelection){
                    t = document.getSelection();
                  }else if(document.selection){
                    t = document.selection.createRange().text;
                  }
                  var el2 = document.getElementById("destination");
                  if (!el2) {
                      alert('no dest element!');
                      return;
                  }
                  el2.value = t;
                    });
                  });
                  function log(obj) {
                    var res="";
                    for(var p in obj) {
                      res += "\n" + p + "=" + obj[p];
                    }
                    return res;
                  }
                  </script>
                  </head>
                  <body>
                  <p id="target">Here is a text paragraph. Here is a text paragraph. Here is a text paragraph. Here is a text paragraph. Here is a text paragraph. Here is a text paragraph. Here is a text
                  paragraph. Here is a text paragraph. Here is a text paragraph. Here is a text paragraph. Here is a text paragraph. Here is a text paragraph. Here is a text paragraph. Here
                  is a text paragraph. Here is a text paragraph. Here is a text paragraph. </p>
                  <textarea id="destination"></textarea>
                  <div id="log" style="font-size:1.5em;background-color:red;color:white;"></div>
                  </body>
                  </html>
                    Write a Reply...