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).

LLB1980Author
Participating Frequently
May 1, 2020

The code provided by try copies the field value when the "Yes" button is pressed, and only then. If the "Rehire_STN_EEID" field contains a value, then it should be copied at that time. But changing the "Rehire_STN_EEID" field value will not change the "STN_EEID" field. 

 

if you want the "STN_EEID" field to automatically update, you'll need to used a Calculation script on the "STN_EEID" field. 


Thank you ...I think I understand what you're both saying...and when I tested, I checked the Yes checkbox and then typed in a number in the Rehire_STN_EEID field - but nothing showed up.

Thom - I tried using a calculation script (might have been a validation script) yesterday, that would check if Rehire_STN_EEID has a value, and if it does, to populate STN_EEID...but I couldn't get this to work.  I'm flexible with "how" this works...ultimately, I just need the employee ID number for any rehires (where "Yes" checkbox is checked) to populate the STN_EEID and then make it read-only.

Here's the link to my PDF (hope it works)

https://drive.google.com/file/d/1FqCiPi5oBNPfUS_xn_t3EtlQDblbo7YB/view?usp=sharing