1

I'm creating a "Complete tasks to unlock" system, but I'm very newbie on coding and can't make it work. I'm literally weeks trying to search ways to do it, but nothing until know. I have only the very basic.

I'll separate all that I need and I really apreciate any help of you guys.

Oh, and I'm using Wordpress and Visual Composer for this.


Well, I already have a code for it (or almost), but isn't working properly as I want.

What I need is that a certain button (.Test) only appear after some completed tasks.

Inittialy, the tasks will be "Visit this link to unlock". So I'll give some buttons, and each button will open a different link. When clicked, the button will trigger the action, unlocking the button to get the cd-keys/links. But the problem is that I need the user click on all the buttons for it. On the code that I'm using, when the user click in just one task button, the .Test appears.

Here's the code that I'm using:

jQuery code

<script>
jQuery(document).ready(function(){
 jQuery('.Like').click(function() {     //Will open a Facebook page
    jQuery('.Test').show();             //Show the button for the link generation
});
 jQuery('.Follow').click(function() {   //Will open a Twitter page
    jQuery('.Test').show();             //Show the button for the link generation
});
});
</script>

CSS code

.Test {
    display: none;
}

.Like,
.Follow {
    cursor: pointer;
}

I tried to use an && operator, but it doesn't work. I need that the user click on all the link buttons to show the button generator. Not just one.

thanks for any help.

If you need more info, please ask me.

2 Answers2

0

One approach would be counting the clicks on these certain buttons, e.g. through storing the buttons in a Set and getting the Sets size:

jQuery(function(){
  var clicked=new Set;//a new unique set
  jQuery('.social').click(function() {     // some button clicked
       clicked.add(this);      //add this button to set
        if(clicked.size>=3) alert("wohoo, all buttons clicked");//actually: three different buttons with class social clicked
  });
});


<button class="social">Twitter</button>
<button class="social">Facebook</button>
<button class="social">GitHub</button>

http://jsbin.com/fanuloxori/edit?output

Note that Sets are quite new, may replace it with an unique array.


You may assign unique ids to the buttons, so you can keep track of the clicked ids, which then can be stored in a database, or on the users device:

jQuery(function(){
  var clicked=new Set((localStorage.getItem("clicked")||"").split(","));//a new unique set may restored from storage
  jQuery('.social').click(function() {     // some button clicked
       clicked.add(this.id);      //add this buttons id to set
       localStorage.setItem("clicked",[...clicked].join(","))
        if(clicked.size>=3) alert("wohoo, all buttons clicked");//actually: three different buttons with class social clicked
  });
});


<button class="social" id="twitter">Twitter</button>
<button class="social" id="facebook">Facebook</button>
<button class="social" id="github">GitHub</button>
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
0

@Jonasw Thank you dude. Using the code bellow without id works fine. Now I have to click on all the buttons (I had set the classes of all for "social") to show the hiden content. But I couldn't use it with the data storage of your second code.

<script>
jQuery(document).ready(function(){
   var clicked=new Set;
      jQuery('.social').click(function() {
         clicked.add(this);
            if(clicked.size>=2) jQuery('.Test').show();
   });
});
</script>