• Mihai

    (@mikymroyahoocom)


    Greetings.
    Thanks for the great plugin, best one yet.
    I have a question how can i leave only the year field to be selected?
    I went to see if i can comment some stuff out in the files … that didn’t go well ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Phil

    (@philsbury)

    Hi @mikymroyahoocom,

    Well at least you gave it a go in the code ??

    At the moment it’s not something that’s possible for various reasons for how the plugin calculates the users age. I’ve had requests to be able to do it in steps i.e if the year would pass then submit and if not check the month next and so on until it either passes or fails but I’ve not had chance to get it properly working as yet.

    Something you could do is use some javascript to add 01 to the day and month fields and then hide them with CSS. Not a perfect solution but might get you near what you want.

    When I get the chance to properly do the stepped input I’ll update you on here.

    Thanks
    Phil

    Thread Starter Mihai

    (@mikymroyahoocom)

    Hey!
    Thanks for the reply. I was thinking yesterday about the same solution.
    I placed this in the header of the theme:

    <script type="text/javascript">
    	function myFunction() {
      	document.getElementById("age-gate-m").value = "01";
    	}
    	</script>

    Doesn’t work.
    I then placed the code in the age-gate-public-display.php file… Doesn’t work.
    I tried adding it in the input-month.php file. Same result.
    Then i tried this code:

    <script type="text/javascript">
    	var textnode = document.createTextNode("01");
      document.getElementById("age-gate-m").appendChild(textnode);
    	</script>

    Obviously, nothing.
    If you can spare 2 minutes to help (pretty sure i am writing the syntax wrong)…
    Thanks a lot ??

    LE. I also tried creating 2 vars, one for the month, one for the text and then tried appending on to the other. Nothing :((((

    • This reply was modified 5 years, 7 months ago by Mihai.
    Plugin Author Phil

    (@philsbury)

    Hi @mikymroyahoocom,

    You’re not far off there, looks like the function never gets called though.

    This in your theme head should do the trick:

    
    function agValue(){
      document.querySelector('#age-gate-d').value = '01';
      document.querySelector('#age-gate-m').value = '01';
    }
    
    window.addEventListener('DOMContentLoaded', agValue);
    

    This works for me on standard and JavaScript modes.

    If you wanted to do this via the wp_head action then use this in your functions:

    
    function headScript(){
      echo '<script>';
      echo "function agValue(){
        document.querySelector('#age-gate-d').value = '01';
        document.querySelector('#age-gate-m').value = '01';
      }
      window.addEventListener('DOMContentLoaded', agValue);";
      echo '</script>';
    }
    
    add_action('wp_head', 'headScript');
    

    Thanks
    Phil

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Leave only the year field input ?’ is closed to new replies.