Copy Text From One Field To Another

The code in that example is what I like to call 'hystorical' (so old in history its funny - from fabrik 2.x).
And good luck figuring out any of the examples in the "Form Javascript" section of the Wiki - and what to do with the so-called fabrik 'javascript object' - because none of the examples seem to work.

So I've given up even trying to use 'straight' javascript in any of the Fabrik javascript plugins and just always go with jQuery.

Assuming the text you want to copy/replace are both fabrik 'field' elements - and the checkbox is a fabrik 'checkbox' element - try this...
Code:
if (jQuery("#tablename___checkbox_element_id input").prop("checked"))
{
    jQuery("#tablename___text2").val(jQuery("#tablename___text1").val());
}

If you want something one line longer and a little easier to understand - this does the same thing...
Code:
if (jQuery("#tablename___checkbox_element_id input").prop("checked"))
{
    var original = jQuery("#tablename___text1").val();
    jQuery("#tablename___text2").val( original );
}

In either case, 'tablename___checkbox_element_id' is the id of the div container that holds the checkbox element
... and 'tablename___text1' and 'tablename___text2' are the id's of the input text 'field' elements.
(Why 'checkbox' elements don't get their own id, and yet 'field' elements do is another question - but that's why you need to add the ' input' after the checkbox's div id.)
 
Thank you Bauer for the response. I tried many ways, but I could not understand how to work this out.

Find a solution with this configuration:

- create a new element label "Proprietario same as Fornecedor" with button plugin
- add javascript Event: mouseup
- add javascript Code:

var Sourcenome = document.getElementById("fb_viaturas___fornecedor_nome");
var Sourcemorada = document.getElementById("fb_viaturas___fornecedor_morada");

var Targetnome = document.getElementById("fb_viaturas___proprietario_nome");
var Targetmorada = document.getElementById("fb_viaturas___proprietario_morada");

txtTargetnome.value = txtSourcenome.value;


Its working
 
No problem. And your javascript solution is probably faster than using jquery - just a little more typing.;)
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top