Skip to main content
first.officer
Inspiring
June 26, 2021
Answered

Copy field value (based on checkbox value), transfer to another field....but with a twist!

  • June 26, 2021
  • 2 replies
  • 3324 views

Hi all,

 

Am curious to know if the follwoing is possible/plausible?.

 

I have a checkbox ("Crsdeferred1a") that when selected, transfers the user entered text value from another field ("Correctives1") to the field ("Correctives1copy"). The script in the "Correctives1copy" field to do this is thus;

 

if (getField("Crsdeferred1a").value=="DEF")
this.getField("Correctives1copy").value = this.getField("Correctives1").value;

 

De-selection of the checkbox ("Crsdeferred1a") leaves the text entered in the field, and is desired to be that way. Of course, if the user changes the text entered in the ("Correctives1") field, then re-selects the checkbox, it updates to the new text, which again is fine.

 

The 'twist' comes with this - is it possible to have a range of fields named "Correctives1copy", "Correctives2copy", "Correctives3copy" - that if the checkbox is re-selected, rather than update any value text-wise that is changed in field "Correctives1" - it then looks to see if any of these 3 fields are empty, and then transfers then entered text ("Correctives1") into an empty (i.e. available) field from the 3?  ("Correctives1copy", "Correctives2copy", "Correctives3copy").

 

So, if i enter the text "deferred iaw 34-09-54A", select the checkbox, this transfers the text (with current script) to the "Correctives1copy" field. All good. If I now de-select the checkbox, re-enter the text, say "No longer an issue.", and then re-select the checkbox - rather than update the value in the field "Correctives1copy" - some script may be looks for the next empty field from the 3 "copy" fields, and enters the new text in to say "Correctives2copy", assuming that field is empty? or if filled previously, then to "Correctives3copy". These copy fields are set to "Read Only", no adjustment possible.

 

A bit unusual I'm sure, any advice greatly received.

 

 

This topic has been closed for replies.
Correct answer bebarth

Try this script or have a look on the attached file and let me know if that is what did you expect.

if (event.target.value!="Off" && this.getField("Correctives1").value!="") {
	for (var i=1; i<=4; i++) {
		if (i==4) {
			app.alert("All copy fields are full");
			break;
		} else if (!this.getField("Correctives"+i+"copy").value.length || this.getField("Correctives1").value==this.getField("Correctives"+i+"copy").value) {
			this.getField("Correctives"+i+"copy").value=this.getField("Correctives1").value;
			break;
		}
	}
}

@+

2 replies

bebarth
Community Expert
bebarthCommunity ExpertCorrect answer
Community Expert
June 26, 2021

Try this script or have a look on the attached file and let me know if that is what did you expect.

if (event.target.value!="Off" && this.getField("Correctives1").value!="") {
	for (var i=1; i<=4; i++) {
		if (i==4) {
			app.alert("All copy fields are full");
			break;
		} else if (!this.getField("Correctives"+i+"copy").value.length || this.getField("Correctives1").value==this.getField("Correctives"+i+"copy").value) {
			this.getField("Correctives"+i+"copy").value=this.getField("Correctives1").value;
			break;
		}
	}
}

@+

first.officer
Inspiring
June 26, 2021

Hi Nesa/Bebarth,

 

Thankyou both so much for the responses, they both work admirably, so very grateful for your help in this! ;-).

Nesa Nurani
Community Expert
Community Expert
June 26, 2021

As Mouse Up event of Checkbox use this:

if(this.getField("Crsdeferred1a").value=="DEF" && this.getField("Correctives1copy").value == "")
this.getField("Correctives1copy").value = this.getField("Correctives1").value;
else if(this.getField("Crsdeferred1a").value=="DEF" && this.getField("Correctives2copy").value == "")
this.getField("Correctives2copy").value = this.getField("Correctives1").value;
else if(this.getField("Crsdeferred1a").value=="DEF" && this.getField("Correctives3copy").value == "")
this.getField("Correctives3copy").value = this.getField("Correctives1").value;