Page 1 of 1

Copy field to another Field after Edit

Posted: Sat Apr 17, 2021 9:57 am
by oli
Hi All,

what is the best way to copy the value of a textarea field (textarea1) to another textarea field (textarea2) on the same form after textarea1 was changed?

Is there any simple solution available?

Thanks in advance and best regards,
Oli

Re: Copy field to another Field after Edit

Posted: Sat Apr 17, 2021 10:00 am
by kev1n
Hi Oli,

Add a Custom Event onchange to your first Textarea object and call:

Code: Select all

$('#other_text_area_id').val($(this).val()).change();

Re: Copy field to another Field after Edit

Posted: Sat Apr 17, 2021 10:30 am
by oli
Thanks a lot!

Re: Copy field to another Field after Edit

Posted: Sat Apr 17, 2021 12:38 pm
by oli
Additionally I tried to set a button to hidden if a specific value of a select field was choosen.
This is was I added to the select object and if the value is "in Planung" the Button should not be visible anymore.
But I guess I still have some errors in the code and I couldn't find an example how to get the value for a specific SELECT object and use it in an IF statement.
screenshot.jpg
BR and thanks in advance, Oli

Re: Copy field to another Field after Edit

Posted: Sat Apr 17, 2021 12:50 pm
by kev1n
Try this:

Code: Select all

function stringsAreEqual(a, b) {
	var a = escape(a).replace(/%20/g, '').replace(/%A0/g, '');
	var b = escape(b).replace(/%20/g, '').replace(/%A0/g, '');
	return a == b;
}

nuShow('run_angebot_print',  ! stringsAreEqual(this.value, 'in Planung') );
If the text and values are different, you need to retrieve the text like this:

Code: Select all

$("#your_select_id option:selected").text();

Re: Copy field to another Field after Edit

Posted: Sat Apr 17, 2021 1:06 pm
by oli
it works :-)
Thank you!

Re: Copy field to another Field after Edit

Posted: Sun Apr 18, 2021 12:40 pm
by oli
Since I have to check various status values and the button should be hidden after the form was accessed it would be easier to hide the button with PHP.
Is there a way to conditionally hide or show objects with PHP as well?

Re: Copy field to another Field after Edit

Posted: Sun Apr 18, 2021 2:06 pm
by kev1n
You will have to use JavaScript. But you could prepare it in BE and run in with nuAddJavascript