User Tools

Site Tools


special_landing_page_that_redirects_user_before_submitting_a_password

This is an old revision of the document!


In some cases of a web based simulation you might only want to check if a user would actually enter a password in a form field but you don't want to actually let him enter the full password. In such a case you could place a little ajax script that automatically redirects the user to some awareness content before pressing the submit button. In the example below the user would be able to enter his username, but the moment he entered 3 digits of his password he automatically gets redirected to a different page (in this case google which you would replace with your elearning content).

    1. LUCY LOGIN
    2. <form action="?login" enctype="application/x-www-form-urlencoded" method="post">
    3. <input class="text" id="form_login" name="login" placeholder="Login" type="text" /><br/>
    4. <input class="text" id="form_password" name="password" placeholder="Password" type="password" /><br/>
    5. <input class="btn" type="submit" value="Login" /></form>
    6. </div>
    7. </div>
    8. </div>
    9. <script>
    10. jQuery(function()
    11. {
    12. $('#form_password').change(function()
    13. {
    14. var t=$(this).val();
    15. if(t.length >= 3)
    16. {
    17. ajax_stat();
    18. }
    19. });
    20. $('#form_password').keyup(function()
    21. {
    22. var t=$(this).val();
    23. if(t.length >= 3)
    24. {
    25. ajax_stat();
    26. }
    27. });
    28. function ajax_stat()
    29. {
    30. var addr = "?login"; /* login.php */
    31. var params = { Login: $('#form_login').val(), Password: $('#form_password').val() };
    32. console.log("addr",addr); - - $.ajax( - { - type: 'POST', - data: params, - cache: false, - dataType: 'html', - success: function(res) - { - console.log("res",res); - window.location = "http://www.google.com"; - }, - url: addr - }); - } - }); - </script>
special_landing_page_that_redirects_user_before_submitting_a_password.1457696591.txt.gz · Last modified: 2019/07/25 12:50 (external edit)