Help with JS for a button element

Status
Not open for further replies.

jfquestiaux

Well-Known Member
I'd like to use for the first a button element to copy the content of a textarea (generated by a calc element) to the clipboard.

I found a simple JS that does that in a way that suits me (without Flash), even though it may look old fashioned (if somone knows a better way, without Flash, I'm open for it), but I have two problems for which I need help:

  1. I pasted the code into the JS box in the JS tab of the button element as illustrated in pic1, but when I save, \ get added before the ' (pic2), which gives me a JS error:

    Erreur : SyntaxError: illegal character
    Fichier Source : http://www.euf.eu.com/trans/media/com_fabrik/js/element-min.js
    Ligne : 1, Colonne : 50
    Code Source :
    function copyToClipboard (text) { window.prompt (\'Copy to clipboard: Ctrl+C, Enter\', text);}

  2. When the \ issue will be resolved, what should I put to replace 'text' by the actual content of my textarea, knowing that its id is '___term'?

pic2.pngpic1.png
 
Not really sure what it is you expect to happen. The js code is already running inside a function (in this case the click function) so what I would expect to happen is to see some code to grab what ever content you wanted to copy and then show the alert . Ie not wrapped inside another function as you currently have it

JavaScript:
var text = document.id('my fields id').value;
alert('do you want to copy ' + text);

of course that in itself (or the code in your screen shot) is not enough to copy to the clipboard - it only shows an alert.
 
Thanks. Well I think I will drop the idea altogether because I realized that you can't do a "ctl-c" on a tablet or a smartphone and the other solution almost all use Flash, witch does not work on tablets or smartphones either.
So what I did, is to tweak the calc element to add a new setting alowing to choose whther or not you wish to add the "disabled" class. If you choose "No", then you are able to copy the content of the calc window.
I will submit a pull request on GitHub for the change.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top