An Auto Selection Puzzler

19 posts by 2 authors in: Forums > CMS Builder
Last Post: July 18, 2014   (RSS)

By gkornbluth - June 9, 2014

So here’s a puzzle for those of you who like such things.

I’m using some foreach loops to generate a series of discrete email lists on a single viewer. Each list has one email address per line, so they tend to get really long really quickly.

Ultimately, I have to copy the list of addresses from the correct list, and paste the list into a PHPList maillist.

Each list on the page is currently delineated by a set of leading and trailing <hr>

The problem that I’d like to overcome is having to click (or tap) and scroll down hundreds of lines to select the addresses in the required list.

 I could probably generate each list on a separate page, but I’d like to try not to do that.

I’d rather be able to click (or tap) at the top of the list and automatically select all the data between the set of <hr> tags. Then it would be a simple matter to copy the selection and paste it into PHPList.

Anyone have an idea?

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By claire - June 10, 2014

Hi Jerry

You can do it with Javascript. Easiest way is to alter the foreach loops so that each email list is inside its own div with a particular ID, like so:

<div id="list1">

email
email
email
email
...

</div>

Then add a button at the top of each list to trigger the selection. Again, amend the foreach loops so that each button gets the right id:

<button onclick="copylist(1)">Copy list</button>

Then here's the Javascript, which you put somewhere in the header:

<script>

function copylist(id)
{
    var text = $("#list"+id).html(); // this gives you everything in the div
    window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}

</script>

Basically this should give you a popup box where you can just hit Ctrl+C. You can't normally access the clipboard directly because of security. Here's the Stackoverflow question about that: http://stackoverflow.com/questions/400212/how-to-copy-to-the-clipboard-in-javascript?lq=1

If you don't know how to amend the foreach loops, just let me know. All you really need to do is start a counter running that increments by one for each list, and then echo the counter in the div line:

<div id="list<?php echo $counter; ?>">

Hope this helps!

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By gkornbluth - June 10, 2014

Thank you Claire,

I'll give it a try. And then add it to my CMSB Cookbook ( http://www.thecmsbcookbook.com ) as a new recipe.

And welcome to the IT Team

Best,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By claire - June 10, 2014

Thanks :) let me know if you have any issues with it.

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By gkornbluth - June 10, 2014

Hi Claire,

Sorry, but obviously I’m doing something wrong.

I started by placing the function in the head of the page as you suggested:

<script>
function copylist(id)
{
    var text = $("#list"+id).html(); // this gives you everything in the div
    window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}
</script>

Then I amended the foreach loop for one list as a test:

<div id="list1">
<button onclick="copylist(1)">Copy list</button>
 <?php foreach ($email_signupRecords as $record): ?>
 <?php if (($record['email'] && $record['hidden'] == 0 && $record['confirmed'] == 1) && ($record['remove']== 0 || $record['remove']== "")): ?>
<?php echo ($record['email']) ?><br />
<?php endif ?>
<?php endforeach ?>
</div>


 

It doesn’t seem to matter if the “Button” is inside the div or outside, or whether I change the button from "copylist(1)" to "copylist(list1)".

When I load the page, all I get is an almost white background button that says Copy List that does nothing when clicked.

You can see the result at http://ericaminer.com/emaillistA.php
Log in with the Cookbook credentials that I sent you.

Thanks for you help,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By claire - June 10, 2014

Hi Jerry

Sorry about this, I thought you were using jQuery for some reason. That solution requires the jQuery libraries.

Here's the function rewritten for vanilla JS:

<script>
function copylist(id)
{
    var divcontents = document.getElementById('list'+id);
    var text = divcontents.innerHTML;
    window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}
</script>

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By gkornbluth - June 10, 2014

Hi Claire,

That certainly works better.

Also turns out the "Button" should be outside the <div> and styling the "Button" took care of the background color.

Just one detail left to sort out.

The line breaks are copied along with the email addresses and change the format of the list from one per line, to plain text with <br> in between each of the addresses.

IE: xxxx@gmail.com<br>yyyy@gmail.com<br>zzzz@gmail.com<br> etc.

When they need to be:

xxxx@gmail.com
yyyy@gmail.com
zzzz@gmail.com
etc.

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - June 11, 2014

Hi Claire,

Sorry to be a pain...

I'm getting closer.

I think you may have reversed the /\n/g and "<br>"

The closest that I could get to something that works is:

<script>
function copylist(id)
{
    var divcontents = document.getElementById('list'+id);
    var text = divcontents.innerHTML;
    var finaltext = text.replace("<br>", /\n/g);
    window.prompt("Copy to Clipboard: CMD (CTL) +C To Copy - Press OK", finaltext);
}
</script>

But there's obviously something still wrong with the syntax, because the result is:

xxxx@cox.net/\n/gyyyy@bizmailtoday.com<br>zzzz@hotmail.com<br>aaaa@gmail.com<br>bbbb@gmail.com<br>etc.

The first <br> gets replaced with /\n/g and the rest are left alone.

Thanks for sticking with this.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By claire - June 11, 2014

Sorry about this Jerry, regex stuff always catches me out for some reason.

Try this:

var finaltext = text.replace("<br>", "\n");

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/