• Resolved hoaboard

    (@hoaboard)


    Hello!
    I am running the following script on my Registration page to automatically populate the username.

    <script type="text/javascript" charset="utf-8">
    function updateUsername(){
      first = document.getElementById("first_name-562").value.toLowerCase();
      last = document.getElementById("last_name-562").value.toLowerCase();
      document.getElementById("user_login-562").value = first+"-"+last;
    }
    </script>

    How can I add the attribute onkeyup="updateUsername();" to the input id of first_name-562 and last_name-562?

    Currently I have manually added the first_name, last_name, and user_login fields by adding them to my registration template. This technically has worked but is causing other issues.

    Here is a picture of how the script and the three input fields are setup currently.

    UM Registration Template Script – register1.php

    Thanks in advance for any help that can be provided!

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @hoaboard

    You can use jQuery for this approach:

    <script type="text/javascript">
    function updateUsername(){
      first = document.getElementById("first_name-562").value.toLowerCase();
      last = document.getElementById("last_name-562").value.toLowerCase();
      document.getElementById("user_login-562").value = first+"-"+last;
    }
    
    jQuery("#first_name-562,#last_name-562").on("keyup",function(){
         updateUsername();
    });
    </script>

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hey there!

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved. …Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. ??

    Regards,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add Attribute to Input ID’ is closed to new replies.