Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
129 views
in Technique[技术] by (71.8m points)

javascript - Showing form input data in a different ID in same form

I have a form with input textboxes with IDs as follows:

#ApplicantFirstName
#ApplicantSurname
#ApplicantAddress
#ApplicantPostcode

Later in the form, there is a consent where I need to show the above details in a statement.

I have the consent as follows:

<p>I <span id="ApplicantFullName"></span> of <span id="ApplicantFullAddress"></span> hereby give my permission for the company to share personal information with other service providers</p>

The function is then triggered on a dropdown being clicked with onclick="updateConsent(); being added to the dropdown.

I have written the following but it's not working:

<script type="text/javascript">
   function updateConsent(){
      document.querySelectorAll("#ApplicantFirstName, #ApplicantSurname").innerHTML = document.getElementById(ApplicantFullName).innerHTML ;
      document.querySelectorAll("#ApplicantAddress, #ApplicantPostcode").innerHTML = document.getElementById(ApplicantFullAddress).innerHTML ;
   }
</script>

Is that the correct script to use?

I'm not getting any errors, just doesn't appear to be working

question from:https://stackoverflow.com/questions/65922390/showing-form-input-data-in-a-different-id-in-same-form

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You use "#ApplicantFirstName, #ApplicantSurname","#ApplicantAddress, #ApplicantPostcode" but your id in the HTML has the first letter as lower case. Note that Javascript is cAsE sEnSiTivE

Change the Javascript:

   function updateConsent(){
      document.querySelectorAll("#applicantFirstName, #applicantSurname").innerHTML = document.getElementById(applicantFullName).innerHTML ;
      document.querySelectorAll("#applicantAddress, #applicantPostcode").innerHTML = document.getElementById(applicantFullAddress).innerHTML ;
   }

OR change the HTML:

<p>I <span id="ApplicantFullName"></span> of <span id="ApplicantFullAddress"></span> hereby give my permission for the company to share personal information with other service providers</p>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...