Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Customize & Extend
Unanswered

Add custom fields to registration site (JavaScript Code)

(0) ShareShare
ReportReport
Posted on by 67

Dear community,

I am having a hard time getting work on a custom code that will add two fields First Name and Last Name to the registration website, below is the code that I had written so far to see if you have any input on it:

 

Content snippet HTML (Account/Register/PageCopy)

 

<script>
 $(document).ready(function() { 
 // Code to add custom First Name and Last Name Fields 
 $('#ContentContainer_MainContent_MainContent_ShowEmail').before('<div class="form-group"><label class="col-sm-4 control-label required" for="FirstNameTextBox"><span id="ContentContainer_MainContent_MainContent_FirstNameLabel"><span class="xrm-editable-text xrm-attribute"><span class="xrm-attribute-value">First Name</span></span></span></label><div class="col-sm-8"><input name="ctl00$ctl00$ContentContainer$MainContent$MainContent$FirstNameTextBox” type="text autocomplete="off" id="FirstNameTextBox" class="form-control" aria-required="true"></div></div><div class="form-group"><label class="col-sm-4 control-label required" for="LastNameTextBox"><span id="ContentContainer_MainContent_MainContent_LastNameLabel"><span class="xrm-editable-text xrm-attribute"><span class="xrm-attribute-value">Last Name</span></span></span></label><div class="col-sm-8"><input name="ctl00$ctl00$ContentContainer$MainContent$MainContent$LastNameTextBox” type="text autocomplete="off" id="LastNameTextBox" class="form-control" aria-required="true"></div></div>');

 //Code to Add Custom 'Register' Button
 $('#SubmitButton').after('<input type="submit" name="ctl00$ctl00$ContentContainer$MainContent$MainContent$mySubmitButton" value="Register" id="mySubmitButton" class="btn btn-primary">'); 
 
 //Hide the original 
 $('#SubmitButton').hide();
 
 $("#mySubmitButton").click(function()
 {
 localStorage.setItem(“firstname”, $(“#FirstNameTextBox”).val());
 localStorage.setItem(“lastname”, $(“#LastNameTextBox”).val());
 
 //trigger standard submit click
 $('#SubmitButton').click(); 
 return false;
 });
 });
 </script>

 

 

I noted that if I delete these two lines below, the fields show in the website otherwise hide, so I presume is an issue with these two lines.

 

localStorage.setItem(“firstname”, $(“#FirstNameTextBox”).val());

localStorage.setItem(“lastname”, $(“#LastNameTextBox”).val());

 

Also, I am planning to use this code for the JS code in the user profile web page:

 

$(document).ready(function() { 
 // get values of First name and last name from local storage and set it in profile form fields.

 var firstname= localStorage.setItem("firstname1"); 
 var lastname= localStorage.setItem("lastname1");

 if(firstname != undefined && firstname != null && firstname != “”)
 {
 $(“#firstname”).val(firstname);
 }
 if(lastname != undefined && lastname != null && lastname != “”)
 {
 $(“#lastname”).val(lastname);
 }

localStorage.clear(); 

});

 

 

Thank you in advance,

 

Jose G Diaz

Categories:

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 69 Super User 2025 Season 1

#2
oliver.rodrigues Profile Picture

oliver.rodrigues 49 Most Valuable Professional

#3
Jon Unzueta Profile Picture

Jon Unzueta 43

Featured topics