• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Copy two field of a form into one

Copy two field of a form into one 7 years 1 month ago #38019

This is a NO-CODER explanation (from a no-coder one person) if your are a experience one, search around cause here I'm going to be as much detailed as i can for dummy's like me!


My case was:
Create a user name field with the joint of two field form, to fill a new field, from two form fields filled, with a special caracter (-) dividing the two captured field forms data.
Apart, the JS would have to do the trick of join two field into one, will be ran only if the user select to create the account selecting a checkbox field and if not, nothing will be done.

Lets start

Create a Checkbox and in name put copy, in caption what ever you need to be shown, with 3 items into it, one for YES (this have to be the first one), other one for NO (the last one) and as you have to trigger the action of the user, create other one (the thrid one I) like "Select an option above[c]" without the quotes, the [c] , will let this option to be the default one, and user will have to click on YES OR NO.
Items parts will look like this:
YES
NO
Select an option above[c]

On additional attributes of this field add this: onclick="copy();" This wil be triggering the JS written down here when user click in an option or not.

Now create 3 TEXTBOX fields, for this example code I'm using in name of the field: cupon , celular and test (this last one is where i want to join the other two fields). It´s important because this is how the fields name are going to interact with the JavaScript.

Replace this names as your needs with the fields you've created, and remember to change them equally in the script part down here!!!!.

Scripting Part!
Add this script to Properties-->Css and JavaScript in the JavaScript part of the option.
the parts on the script with // are comment and won't be shown in the form result view, you can erase them.

<script type="text/javascript">
//This is the name of the function.
function copy(){
  //This is the check box option where i want if selected by the user, the data to be copied to the form field "test" you don't have to replace the "copy0" or "copy1" part of the script, just cupon, celular and test parts. I have also added a pop up screen of confirmation with OK button to see if this is working, if you don't want that, just erase, by the way the information got to be copied to the test field. Here is the alert par of the code if want to remove:   alert(document.getElementById('test').value);   from the script. 
 
if (document.getElementById("copy0").checked==true)
    {
// Define a variable for the cupon field.
var cupon = document.getElementById('cupon').value;
// Define a variable for the celular field.
var celular = document.getElementById('celular').value;
//This is joint field taking VAR cupon and VAR celular into one. plus I've added a '-' sign to split the result format view.
document.getElementById('test').value = cupon+'-'+celular;
// This is a pop windows with field joint format on screen
alert(document.getElementById('test').value);
    }
    //my checkbox got two options. So first one is "copy0" second one is "copy1" and if they choose second one, no joint will be done.
    else if (document.getElementById("copy1").checked==true)
    {
    document.getElementById("cupon").value="";
    document.getElementById("celular").value="";
    }
}
</script>
Till here we can say your done!

If you want to joint more...
NOTE: If you want to join more fields use this (assuming the new field you will be adding is name: namefieldyouhaveusedinrsform ):

Add a: var newfieldname = document.getElementById('namefieldyouhaveusedinrsform').value; just below tha lastone in the script.

Once your are done with adding fields, just simply add them the joining field, where you just have to add a plus sign + between them with no spaces.

Change this line adding + sign between fields defined in vars Example of the line:

document.getElementById('test').value = cupon+celular+newfield; As you see here i use the name in var definitions and no the field name in rsformPro!

Change this into this line of the script with the new one you have added.
document.getElementById('test').value = cupon+'-'+celular;

Hope this was helpful, i'm not a coder and sometimes tuts around there are so confusing for people like me, so I have tried to be really clear, if not comment here and I will try to help.

Thank you RSJoomla for such a beautiful component! And to all of you... Share that's how the whole thing is done.
Last Edit: 7 years 1 month ago by ddemarchi@bmcm.com.mx.
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!