• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

How assign a value to an element from another one

F.schettino

Italian
(I am sorry for my bad English).

I don't know php and Javascript :(
I need assign a value to an element (called Importo) after depending on value inserted in another (IdEvento); I have to read the value to insert from a table (Fabrik_Eventi_Soci) using a Select (Select Importo from Fabrik_Eventi_Soci where id=id_Evento).

I red an example and documentation and I tried using event Change Javascript of the element IdEvento:
var $id_Evento_Usato = $('fabrik_movimenti_contabilita___IdEvento');​
var id_Evento = $id_Evento_Usato.textContent || $id_Evento_Usato.innerText;​
/*​
I used also var id_Evento = $id_Evento_Usato.value;​
instead of previous statement​
*/​
fabrik_movimenti_contabilita___Importo = 'Select Importo from Fabrik_Eventi_Soci where id=' + id_Evento;​
but it doesn't work.

Can someone help me?
 
$formModel->updateFormData('table_elementname', 'your_value', true);

The above code goes in forms->plugins->php
 
I have a table in which there is a value of "Importo" for each value of "IdEvento".
I need preset a value in an element (Importo) of a form/list when a value in inserted in another element (IdEvento), not when the form/list is opened or adding a button; so I think that I have to use: Element--->JavaScript--->event Change
Is it correct?

I don't know what is wrong in my code (I don't know php and Javascript; I search examples when I need php or Javascript statements).

Can you help me?
 
I used also:
var id_Evento= 'fabrik_movimenti_contabilita___IdEvento';​
fabrik_movimenti_contabilita___Importo = 'Select Importo from Fabrik_Eventi_Soci where id=id_Evento';​
Is it possible verify code step by step?
 
Are you using a dropdown element? Coun you attached a screenshot so that I can see which are your elements and which one of them should trigger. If its just to copy the value from one element to another you can use the following. On element1 javascript plugin (onchange)
Code:
$('your_element2').value = $('your_element1').getValue();
 
Thank you for your help, jgarcia.

In picture 4 you can see the form; 2 (Importo) is the field in which insert a value when a value is choosen in 1 (IdEvento).
In pictures 1,2,3 you see the definition of IdEvento.

I think that the mistake is in the statement
var $risultato_query = mysql_query("select importo from Fabrik_Eventi_Soci where id="+id_Evento);​
because I tried
var id_Evento = fabrik_movimenti_contabilita___IdEvento.value;​
fabrik_movimenti_contabilita___Importo.value = id_Evento;​
and the value id_Evento is written in Importo.

If I try
var id_Evento = fabrik_movimenti_contabilita___IdEvento.value;​
var $risultato_query = mysql_query("select importo from Fabrik_Eventi_Soci where id="+id_Evento);​
var importo = mysqli_fetch_field_direct($risultato_query,0);​
fabrik_movimenti_contabilita___Importo.value = importo;​
no value is inserted in fabrik_movimenti_contabilita___Importo.

Can you tell me what is wrong?

Thank you.
 

Attachments

  • 1.png
    1.png
    16.1 KB · Views: 334
  • 2.png
    2.png
    7.9 KB · Views: 335
  • 3.png
    3.png
    15.8 KB · Views: 324
  • 4.png
    4.png
    30.6 KB · Views: 327
You just need the selected value of Evento in Importo. Add the code provide on the Evento element javascript with a OnChange. (below is the code
Code:
$('elk_mytests___importo').value = $('elk_mytests___evento').getValue();
)
 

Attachments

  • evento01.png
    evento01.png
    51.7 KB · Views: 306
  • evento02.png
    evento02.png
    58.9 KB · Views: 300
Sorry, probably I am not clear.
My question is: what is wrong in followings statements?

var id_Evento = fabrik_movimenti_contabilita___IdEvento.value;
var $risultato_query = mysql_query("select importo from Fabrik_Eventi_Soci where id="+id_Evento);
var importo = mysqli_fetch_field_direct($risultato_query,0);
fabrik_movimenti_contabilita___Importo.value = importo;
Can you help me?
Thank you.
 
PLEASE, HELP ME!
(Modified)

I tried also:

id_Evento = fabrik_movimenti_contabilita___IdEvento.value;​
testoSQL = "SELECT Importo FROM Fabrik_Eventi_Soci WHERE Id='" + id_Evento + "'";​
alert("testoSQL= "+testoSQL); /* The pop-up is shown: SELECT Importo FROM Fabrik_Eventi_Soci WHERE Id='2' */
query= mysql_query(testoSQL); /* I tried also: query= mysql_query(testoSQL,1); */
alert("After query= "); /* The pop-up is not shown that means the execution stops: the previous statement is wrong! */
while(risultati_query = mysql_fetch_array(query))​
{​
Importo= risultati_query["Importo"];​
alert("Importo= "+Importo); /* The pop-up is not shown */
fabrik_movimenti_contabilita___Importo.value = Importo;​
}​
How have I to modify?
 
Hi,

If the code that you gave is exactly what you have put in, then i think you should check all the variables. You may have forgotten the "$" before the variable. Example :
Your Line: testoSQL = "SELECT Importo FROM Fabrik_Eventi_Soci WHERE Id='" + id_Evento + "'";
Shouldnt it be: $testoSQL = "SELECT Importo FROM Fabrik_Eventi_Soci WHERE Id='" + $id_Evento + "'";
 
I am having a problem with this too.


(1) Need to copy the values of Office Address to Communication Address as shown in "copyover needs.png" screen cap (attached).
(2) The js code for the YESNO is shown in "jscode.png" screen cap attached.
(3) It works for the Street Address (text field) but not for the City (cascading dropdown).

Please help. Thank you.
 

Attachments

  • Copyover Needs.png
    Copyover Needs.png
    18.9 KB · Views: 148
  • jscode.png
    jscode.png
    27.2 KB · Views: 154
For dropdown elements need to use table_name___element_name_raw(value of dropdown element instead of html/text value).
 
Hi StartPoint,

None of these lines seem to work:

$('clnet_lkp_supplier___suppcomms_state_raw').value = $('clnet_lkp_supplier___suppoffice_state').getValue();
$('clnet_lkp_supplier___suppcomms_city_raw').value = $('clnet_lkp_supplier___suppoffice_city').getValue(); $('clnet_lkp_supplier___suppcomms_postcode_raw') = $('clnet_lkp_supplier___suppoffice_postcode').getValue();

What is wrong with these js codes? Please help. Thank you.
 
I don't know what is wrong.
Look in js errors in your browser console.
I think you write this code in element js tab.
I use form_X.js files to write my own codes and I don't use fabrik element js.
 
Thank you Startpoint. Does anyone here know how to copy the values of an element to another element? Or is it that it cannot be done? I am wasting good number of man hours on this and i hoping it wont be a show stopper.

Appreciate all the help i can get. Thank you.
 
The HTML ids are without _raw, inspect your page source, _raw is in (php) element placeholders.

This is general JS nothing special Fabrik.
To set an <option in <select to "selected" (e.g. for dbjoin or cdd) set the selectedIndex, try (assuming both elements have the identical options, which may be not the case if you are using CDDs which are watching other elements)
$('clnet_lkp_supplier___suppcomms_city').selectedIndex = $('clnet_lkp_supplier___suppoffice_city).selectedIndex;


For JS (and CSS) always inspect your page source with your browser dev tools.
 
I manage to solve the problem. CDDs in the comms address were watching each others comms values. I changed it to watch the office values and it worked. It is fine when i copy the office address to the communication address. But subsequently when i want to change the state or city in the comms address, the CDD still keeps watching the Office. I find that this renders the copy feature to be useless. Conclusion: To get this working i may have to rewrite the code with custom code or have to redesign the application features. If i accept this, then someone must always be aware of what the previous heck was. Terrible, sigh!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top