Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post

    Enable button after all link clicks?

    Well.. I've seen it done before, but I don't really have any experience with Javascript.

    How would I make a code where, for example, i have about 5 links on a page, and there is a submit button. The submit button is disabled until all 5 links are clicked?

  2. #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,938
    Thanks
    211
    Thanked 2,624 Times in 2,602 Posts
    You will need to use a cookie. Clicking on the links changes the page.

    Warrington are running around like limpet mines. - Commentator Sky Sports

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  3. #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Philip M View Post
    You will need to use a cookie. Clicking on the links changes the page.
    Huh? I don't want it to change the page, I want to have 5 hyperlinks on a page, and they all open in new tabs, and after all 5 are clicked, it makes the submit button visible.

  4. #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,477
    Thanks
    57
    Thanked 633 Times in 628 Posts
    can you show your html?
    what happens if a link is clicked a second time?
    is it one click on each of the five links, or can one link be clicked 5 times?

  5. #5
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by xelawho View Post
    can you show your html?
    what happens if a link is clicked a second time?
    is it one click on each of the five links, or can one link be clicked 5 times?
    I have no html yet, but i was thinking something like an onclick, and each time you click a link it adds 1 to a value.. then if the value is equal to 5 then it shows the submit button.
    All links should only be clickable once

  6. #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,477
    Thanks
    57
    Thanked 633 Times in 628 Posts
    something like this I guess...

    Code:
    <a href="http://www.google.com" target="_blank" onclick="countClicks(this)"/>google</a>
    <script type="text/javascript">
    var count=0;
    function countClicks(thelink){
    thelink.onclick=function(){return false;}
    count++
    if (count==5){
    document.getElementById("thebutton").disabled=false;
    	}
    }
    </script>

  7. Users who have thanked xelawho for this post:

    markman641 (09-10-2012)

  8. #7
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Didnt seem to work.. am i doing something wrong?

    Code:
    <a href="http://www.google1.com" target="_blank" onclick="countClicks(this)"/>google</a>
    <a href="http://www.google2.com" target="_blank" onclick="countClicks(this)"/>google</a>
    <a href="http://www.google3.com" target="_blank" onclick="countClicks(this)"/>google</a>
    <a href="http://www.google4.com" target="_blank" onclick="countClicks(this)"/>google</a>
    <a href="http://www.google5.com" target="_blank" onclick="countClicks(this)"/>google</a>
    <div id="thebutton" style="display:none;"><a href="http://www.google5.com" target="_blank"/>asdfasdfasdfe</a></div>
    
    <script type="text/javascript">
    var count=0;
    function countClicks(thelink){
    thelink.onclick=function(){return false;}
    count++
    if (count==5){
    document.getElementById("thebutton").disabled=false;
    	}
    }
    </script>

  9. #8
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,477
    Thanks
    57
    Thanked 633 Times in 628 Posts
    no, no - I just misunderstood you. When you said you wanted to enable a button I thought you meant that you wanted to enable a button. My bad. If you want it to show an element that is currently hidden with display:none, it would look more like this:

    Code:
    <script type="text/javascript">
    var count=0;
    function countClicks(thelink){
    thelink.onclick=function(){return false;}
    count++
    if (count==5){
    document.getElementById("thebutton").style.display="block"; //or inline or whatever
    	}
    }
    </script>

  10. Users who have thanked xelawho for this post:

    markman641 (09-10-2012)

  11. #9
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    Quote Originally Posted by xelawho View Post
    no, no - I just misunderstood you. When you said you wanted to enable a button I thought you meant that you wanted to enable a button. My bad. If you want it to show an element that is currently hidden with display:none, it would look more like this:

    Code:
    <script type="text/javascript">
    var count=0;
    function countClicks(thelink){
    thelink.onclick=function(){return false;}
    count++
    if (count==5){
    document.getElementById("thebutton").style.display="block"; //or inline or whatever
    	}
    }
    </script>
    Sweet! Worked like a charm. You rock dude


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •