How to get mirror values from one field to another when checkbox is checked in webpage | Community
Skip to main content
Level 4
October 29, 2021
Question

How to get mirror values from one field to another when checkbox is checked in webpage

  • October 29, 2021
  • 1 reply
  • 1053 views

Hi All,

We are trying to get mirror value from one field to another when a checkbox is checked.

While trying we are getting issues as mentioned below.

1. when checkbox is checked and webpage is submitted, the 2nd field (the field in which the values came as mirror from 1st field) is showing validation/mandatory issue.

2. If we just select the 2nd field in webpage after checking the checkbox and the mirror values is taken in to 2nd field the validation/mandatory issue is not coming and able to submit the form.

 

Can someone please help resolve this issue ASAP?

 

Thanks & Regards,

Greeshma

@_manoj_kumar_ @davidkangni @debtr @marcel_szimonisz 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Level 4
October 29, 2021

1st field code:

<li><label class="desc" id="title1">First Name <span class="req" id="req_4">*</span></label>
<div><input name="fname" class="inputwidth" id="fname" type="text" placeholder="First Name" data-nl-bindto="xpath" data-nl-xpath="@firstName" data-nl-ismandatory="true" data-nl-label="First Name" /></div>
</li>

2nd field code:

<li><label class="desc" id="title1">First Name <span class="req" id="req_4">*</span></label>
<div class="inputwidth"><input name="fname2" class="fname2" id="fname2" type="text" placeholder="First Name" data-nl-bindto="xpath" data-nl-xpath="@firstName2" data-nl-ismandatory="true" data-nl-label="First Name" /></div>
</li>

 

Mirroring script:

$("#mirror").change(function() {

var checkbox = document.getElementById('mirror').checked ;
if(checkbox = true){

var Pfirstname = document.getElementById("fname").value;


var Afirstname = Pfirstname;


document.getElementById("fname2").value = Afirstname;
}
else
{
document.getElementById("fname2").value = '';

}
});