[SOLVED] How copy fieldvalue to another fieldvalue ?

13 years 6 months ago #142957 by famq23
Hello CB,

In the register form, i have a two field identification document:

I. Document 1 and I. Document 2

First, i enter the value in the Identification Document, then, how copy the value of 1st field Indentification Document to 2nd field without writing the Second field ?

Can this in Javascript or Ajax ?

Thanks.

Post edited by: krileon, at: 2010/09/30 19:01

Please Log in to join the conversation.

13 years 6 months ago #143025 by krileon

Can this in Javascript or Ajax ?

Yes, you'll need to use JS in a new CB plugin using CB triggers to render it on the registration form (or editing your template directly and adding the JS to the registration function) to copy the value. jQuery can also be used instead of standard JS if you want more cross browser capability, etc..


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

13 years 6 months ago #143042 by famq23
Thanks Krileon,

In this moment, am editing the templates for frontend (components/com_comprofiler/plugin/templates/default/default.php) and i insert the function in JS with getElementById:

[code:1]
function copy(from,to){
document.getElementById(to).value = document.getElementById(from).value;
}
[/code:1]

And the field copy to another field with button:

[code:1]
<input type="button" value="Copy field Identification" onclick="copy('username','cb_cedula'); ">
[/code:1]

But, i like not this, else that the idea is that the user first enter the field value and to click in the second field to copy, automatically copy, and this no not need the copy button.

A problem, logic, in Dreamweaver maker the form, in the input text can insert the 'onclick' atribute, but in the Register Form i can not insert the atribute onclick in the input text because is automatic generated.

And another question, where is for modify the template for Backend, for insert the JS function ?

Thanks.

Please Log in to join the conversation.

13 years 6 months ago #143068 by krileon
The following jquery example will do what you're wanting.

[code:1]
$js = "$( '#input2id' ).click( function() {"
. "$( '#input2id' ).attr( 'value', $( '#input1id' ).val() );"
. "});";

$_CB_framework->outputCbJQuery( $js );
[/code:1]

Ensure you change input2id to the actual field id of the field you want to populate. Change input1id to the id of the field you're grabbing the value from.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

13 years 6 months ago #143092 by famq23
Thanks Krileon,

The code in Jquery works perfect, in the frontend form register, two field yes copy 1st field value to 2nd fieldvalue, perfect.

But, need put the code in the Backend CB User Register Form, then, what is the name of file in php to modify e insert the JQuery ?

Bye.

Please Log in to join the conversation.

13 years 6 months ago #143101 by famq23
Ready, i found the file in the route:

administrator/component/com_comprofiler/library/cb/cb.tables.php

in the final of code, before of ?> i put the JQuery code, and work perfect :)

Thanks.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.193 seconds

Facebook Twitter LinkedIn