Title: Add Attribute to Input ID
Last modified: May 25, 2021

---

# Add Attribute to Input ID

 *  Resolved [hoaboard](https://wordpress.org/support/users/hoaboard/)
 * (@hoaboard)
 * [5 years ago](https://wordpress.org/support/topic/add-attribute-to-input-id/)
 * 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](https://imgur.com/a/Q57Vs5j)
 * Thanks in advance for any help that can be provided!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadd-attribute-to-input-id%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [5 years ago](https://wordpress.org/support/topic/add-attribute-to-input-id/#post-14484702)
 * Hi [@hoaboard](https://wordpress.org/support/users/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](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [5 years ago](https://wordpress.org/support/topic/add-attribute-to-input-id/#post-14506904)
 * 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.

 * ![](https://ps.w.org/ultimate-member/assets/icon-256x256.png?rev=3160947)
 * [Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin](https://wordpress.org/plugins/ultimate-member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-member/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-member/reviews/)

## Tags

 * [attribute](https://wordpress.org/support/topic-tag/attribute/)
 * [input](https://wordpress.org/support/topic-tag/input/)
 * [Registration](https://wordpress.org/support/topic-tag/registration/)
 * [script](https://wordpress.org/support/topic-tag/script/)
 * [user_login](https://wordpress.org/support/topic-tag/user_login/)

 * 2 replies
 * 2 participants
 * Last reply from: [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/add-attribute-to-input-id/#post-14506904)
 * Status: resolved