The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Copy the value of a field to another field with a link click
Hi,
Can anyone help with some suggested code for the following:
I'm trying to help users complete a form of mine by speeding up the process. I want users to be able to copy the value of a field into another field with a click of a link.
So for example: FIELD 1 - "value of field 1" > click to copy > FIELD 2 - "value of field 1"
February 1, 2019 at 8:01 am
You would do this with jQuery, a simple example is:
<script>
jQuery(document).ready(function ($) {
"use strict";
// monitor field 1 for changes
$('#field_id1').on('change', function() {
var val1 = $(this).val();
// assign the value to field 2
$('#field_id2').val(val1);
});
});
</script>
To use this, change the field ids to your field ids for field 1 and field 2 and save it to the after fields area on the form's customize HTML page.
February 1, 2019 at 6:24 pm
Thanks vfontjr
I've placed this code in the form's customize HTML page for but its not working for fields ID104 and IS105 in my form.
I've tried:
$('field_[104]').on('change', function() {
and
$('[104]').on('change', function() {
and
$('#104').on('change', function() {
but the the inputted data in field 104 is not copying/displaying in field 105....
Can you offer further assistance...
<script>
jQuery(document).ready(function ($) {
"use strict";
// monitor field 1 for changes
$('field_[104]').on('change', function() {
var val1 = $(this).val();
// assign the value to field 2
$('field_[105]').val(val1);
});
});
</script>
February 1, 2019 at 6:38 pm
I have also tried the following javascript code:
<script type="text/javascript">
$(document).ready(function () {
$("field_[key]").keyup(function () {
var value = $(this).val();
$("field_[key]").val(value);
});
});
</script>
February 1, 2019 at 10:25 pm
If you use your browser's built-in inspection tool to view the form's source, you can find the exact element id for the fields you want to work with.
When the HTML for the form is generated for the browser, every field is assigned an HTML id that is comprised of field_ plus the field's key. You're trying to make the jQuery work with by adding the field's ID to the word field_. HTML IDs and field IDS are completely different things.
You also removed the # that identifies the string as an element ID in jQuery.
If you post a link to the form and tell me which fields you want copied, I'll give you the exact jQuery.
February 2, 2019 at 4:15 pm
Mate,
Brilliant work!
Many thanks for your help - you're advice/script worked a treat...!
For further reference for others wanting to do this, the modified script I used is below which may be of help to others. (In my example, I had to add the the following field id's) and as suggested above, I got those from looking at the browser html code...
<script>
jQuery(document).ready(function ($) {
"use strict";
// monitor field 1 for changes
$('#field_yxun5-0').on('change', function() {
var val1 = $(this).val();
// assign the value to field 2
$('#field_abj6c-0').val(val1);
});
});
</script>
Many thanks...
Discussion closed.