Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Engaged ,
Jun 26, 2021 Jun 26, 2021

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.

 

 

TOPICS
PDF forms
3.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Jun 26, 2021 Jun 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;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2021 Jun 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;
		}
	}
}

@+

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2021 Jun 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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2021 Jun 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;
		}
	}
}

@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 26, 2021 Jun 26, 2021

Hi Nesa/Bebarth,

 

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 26, 2021 Jun 26, 2021

What if he changes value if checkbox is still checked it will enter new value immediatelly or when all fields are full and checkbox is unchecked he will still get alert.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2021 Jun 26, 2021

With my script you can't get twice the same text and you have a message when all fields are full.
@+

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 26, 2021 Jun 26, 2021

If all fields are full you get message all the time, you need to fix that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2021 Jun 26, 2021

@Asim123 script goes to checkbox not text field 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 26, 2021 Jun 26, 2021

Lol sorry about that @bebarth I thought script goes into calculation as OP had it in one.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 12, 2021 Aug 12, 2021

Hi, I am using similar code as bebarth has given above; 

 

if (event.target.value!="Off" && this.getField("Value1").value!="") {
	for (var i=1; i<=4; i++) {
		 if (!this.getField("Value"+i+"copy").value.length || this.getField("Value1").value==this.getField("Value"+i+"copy").value) {
			this.getField("Value"+i+"copy").value=this.getField("Value1").value;
			break;
		}
	}}

However, I am trying to pull numbers - not text. What am I doing wrong?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 12, 2021 Aug 12, 2021

@bebarth  if you have any idea?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 12, 2021 Aug 12, 2021

In this part try add 'AsString':

"Value"+i+"copy").valueAsString.length

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 12, 2021 Aug 12, 2021

Thank you so much! Would you believe I tried AsString myself everywhere in the code - except for there... Appreciate it 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 16, 2021 Aug 16, 2021

Hi again,

 

How do I change this code so that it does as previously but even when values/text are the same? As in; I am using the code for inputting initials into a box and the code doesn't fill the boxes if the initials are the same e.g. LJ only fills once and not again for LJ

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 05, 2023 Oct 05, 2023
LATEST

Hello Nesa, I'm hoping you can help as I am new to this.

I have a sheet where I simply want to add the EXT Price that populates from QYT x Price to the Text 3 box when the check Box is selected and be empty when you uncheck it.

The Ext Price function works but the check box is not.

Ken32745457tjfv_0-1696538959693.png

I have entered code on the check Box mouse up fucntion but can't get it ti copy over and comes up NULL.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines