Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

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

Greeshma_Sampath1
Level 4
Level 4

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 @Deb007 @Marcel_Szimonisz 

1 Reply
Greeshma_Sampath1
Level 4
Level 4

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 = '';

}
});