Results 1 to 6 of 6

Thread: Remove hide button from show in show/hide div script

  1. #1
    Join Date
    Feb 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Remove hide button from show in show/hide div script

    Found this great script, it has button that show contents of div when clicked and the button changes to hide div button.
    it starts all over with show div button on page load so works great.

    my problem is i donīt need the second button

    my plan is using it in combination of captcha script,
    where captcha is hidden until user clicks button, hoping making it harder for bots.
    and others that make fake registrations.

    i already have integrated captcha script that generate the captcha
    and its that div i hide with the script.

    think my solution can benefit all that is using captcha adding extra layer of security to it,
    at least i hope it does

    Code:
    <script type="text/javascript">
        var button_beg = '<button id="button" onclick="showhide()">', button_end = '</button>';
        var show_button = 'Show captcha', hide_button = 'Hide captcha';
        function showhide() {
            var div = document.getElementById( "hide_show" );
            var showhide = document.getElementById( "showhide" );
            if ( div.style.display !== "none" ) {
                div.style.display = "none";
                button = show_button;
                showhide.innerHTML = button_beg + button + button_end;
            } else {
                div.style.display = "block";
                button = hide_button;
                showhide.innerHTML = button_beg + button + button_end;
            }
        }
        function setup_button( status ) {
            if ( status == 'show' ) {
                button = hide_button;
            } else {
                button = show_button;
            }
            var showhide = document.getElementById( "showhide" );
            showhide.innerHTML = button_beg + button + button_end;
        }
    	
        window.onload = function () {
            setup_button( 'hide' );
            showhide(); // if setup_button is set to 'show' comment this line
        }
    </script>
    
       <div id="showhide"></div>
       <div id="hide_show">captcha</div>
    i have tried lots of scripts but its only one i could find that works close to what i want
    and spend couple of hours trying solving it my self but i cant figure it out.
    Last edited by Dahls; 03-04-2017 at 04:26 PM. Reason: merge posts

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Do you have some sort of code on the page designed to prevent code injection and/or DOM manipulation from the console or other places other than that hard coded to the page and its scripts? The reason I ask is I had several ideas for this, but when I tried it out in the console, the form would submit before I had a chance to see the captcha, so they appear useless.

    Oh, and bots don't use style, so they will "see" the captcha anyway. In order to catch bots, usually the opposite is done. A form field hidden from users by style is labeled as "required". If a bot reads the page, it will fill it out. Humans won't see it, so if it's filled in, you know it's a bot.

    Combining that technique with a high quality captcha, which you already have, should be fine. Hiding and showing it is meaningless to bots though, and a nuisance for real people.
    Last edited by jscheuer1; 03-04-2017 at 06:27 PM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ok thank you for your advice and for looking at it
    Last edited by Dahls; 03-04-2017 at 07:02 PM.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If you still want to do this, I discovered a method that appears to work in the console (change highlighted):

    Code:
    <script type="text/javascript">
        var button_beg = '<button id="button" onclick="showhide();">', button_end = '</button>';
        var show_button = 'Show captcha', hide_button = 'Hide captcha';
        function showhide() {
            var div = document.getElementById( "hide_show" );
            var showhide = document.getElementById( "showhide" );
            if ( div.style.display !== "none" ) {
                div.style.display = "none";
                button = show_button;
                showhide.innerHTML = button_beg + button + button_end;
            } else {
                div.style.display = "block";
                button = hide_button;
                showhide.removeChild(document.getElementById('button'));
            }
        }
        function setup_button( status ) {
            if ( status == 'show' ) {
                button = hide_button;
            } else {
                button = show_button;
            }
            var showhide = document.getElementById( "showhide" );
            showhide.innerHTML = button_beg + button + button_end;
        }
    	
        window.onload = function () {
            setup_button( 'hide' );
            showhide(); // if setup_button is set to 'show' comment this line
        }
    </script>
    I think there are "better ways", but, as I said before, they triggered the form submission before the captcha could be used. If that was due to something you know about, we can maybe work with it. But, for now, if you still want this, I think the above would likely be the way to go.

    A variation on this is (also works in the console):

    Code:
    <script type="text/javascript">
        var button_beg = '<button id="button" onclick="showhide();">', button_end = '</button>';
        var show_button = 'Show captcha', hide_button = 'Hide captcha';
        function showhide() {
            var div = document.getElementById( "hide_show" );
            var showhide = document.getElementById( "showhide" );
            if ( div.style.display !== "none" ) {
                div.style.display = "none";
                button = show_button;
                showhide.innerHTML = button_beg + button + button_end;
            } else {
                div.style.display = "block";
                button = hide_button;
                showhide.style.height = showhide.offsetHeight + 'px';
                showhide.removeChild(document.getElementById('button'));
            }
        }
        function setup_button( status ) {
            if ( status == 'show' ) {
                button = hide_button;
            } else {
                button = show_button;
            }
            var showhide = document.getElementById( "showhide" );
            showhide.innerHTML = button_beg + button + button_end;
        }
    	
        window.onload = function () {
            setup_button( 'hide' );
            showhide(); // if setup_button is set to 'show' comment this line
        }
    </script>
    That one preserves the space which the button had occupied.
    Last edited by jscheuer1; 03-05-2017 at 01:09 AM. Reason: add variation
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Feb 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    thank you for the code but you were right about my buttons they did not prevent the bot, if it is a bot who can tell

    i love that code so i using it again at least until customers criticize they has to click show caprcha
    Last edited by jscheuer1; 03-05-2017 at 12:42 PM. Reason: merge posts

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm not sure how one can tell if it's a bot. What makes you think it is? Is it doing anything odd, like sending you spam? You should be able to block its ip address unless it it keeps changing it.

    Using the hidden field strategy should catch it if it is a bot. For example, I see you have an email field, you could add:

    Code:
    <input type="text" name="sender_email" size="32" value="" placeholder="Email"><br>
    <br>
    <input type="text" name="confirm_email" size="32" value="" placeholder="Confirm email">
    Then in the stylesheet have:

    Code:
    input[name="confirm_email"] {display: none;}
    That way, only bots should see it. If that's filled out, have the form not validate. You do have form validation, right?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Show/Hide the 'x' button on the modal window based on our needs?
    By kmantrip in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 06-12-2014, 05:24 PM
  2. Replies: 1
    Last Post: 02-24-2012, 03:59 AM
  3. Simple Show/hide script
    By Wisdom in forum Looking for such a script or service
    Replies: 2
    Last Post: 12-22-2010, 03:51 PM
  4. need a show/hide div script!
    By hmsnacker123 in forum Looking for such a script or service
    Replies: 2
    Last Post: 04-19-2008, 09:11 PM
  5. show hide div (hide last open div)
    By flash in forum JavaScript
    Replies: 5
    Last Post: 12-24-2007, 08:57 PM

Bookmarks

Posting Permissions

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