web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Add custom fields to r...
Power Pages
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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Pages

#1
M Bilal Khan Profile Picture

M Bilal Khan 139

#2
Mohsin Ali Profile Picture

Mohsin Ali 41

#3
11manish Profile Picture

11manish 19 Super User 2026 Season 2

Last 30 days Overall leaderboard