Skip to main content
Participating Frequently
May 1, 2020
Question

How can I use a checkbox export value to copy text field value (text1) into another text field?

  • May 1, 2020
  • 1 reply
  • 5063 views

I have mutually exclusive checkboxes...one with export value of No, and the other with export value of Yes.

Nothing happens if no checkbox is selected - but if the Yes checkbox is selected, I want javascript that will copy the value of text1 into text2 and make text2 read-only.

If the yes box is un-checked, I want text 2 to be an editable text field again.

Can anyone help me? I've searched and modified few different scripts I found online, but nothing is working 100%.

Thanks in advance for any help!

 

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
May 1, 2020

As the Mouse Up event of the check-box fields enter this code:

 

if (event.target.value=="Yes") {
	this.getField("text 2").value = this.getField("text 1").value;
	this.getField("text 2").readonly = true;
} else {
	this.getField("text 2").value = "";
	this.getField("text 2").readonly = false;
}

 

LLB1980Author
Participating Frequently
May 1, 2020

Thank you @Try67...when I use the code, I can see that something is happening because when I test and check the "Yes" checkbox, my field shading for text2 goes away, but the actual text from text1 is not showing?

Can you review and advise if I have an error - or another suggestion? Thank you!!

Here's the code (modifed yours with my actual field names):

 

//If person is rehire, copy rehire EEID to STN_EEID text field, and make Read-only
if (event.target.value=="Yes") {
	this.getField("STN_EEID").value = this.getField("Rehire_STN_EEID").value;
	this.getField("STN_EEID").readonly = true;
} else {
	this.getField("STN_EEID").value = "";
	this.getField("STN_EEID").readonly = false;
}

 

 

(note my checkbox is named "Rehire" - different name than text field).

try67
Community Expert
Community Expert
March 4, 2022

hi, try67

i am using exact code that you provided, it is in the Checkbox field, MouseUp and Run a Java Script. I would like copy Name1 to Name2 when the Checkbox is clicked ( the Export value is "Yes"). My problem is after i entered value in the Name1, clicked the Checkbox, nothing populated. it doesn't seem to recognize the value of the Checkbox. Appreciate your help. 


Double-check the field names, and also the JS Console for error messages.

If you can't see any errors, share the file for further help.