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