Page 1 of 1
Use of javascript magic hooks
Posted: 2014-06-11 16:42
by gerardus
Hi all,
Could the "magic" javascript described here
http://bigprof.com/appgini/help/advance ... agic-files be used to set field values when another field changes?
If so, is there a reference somewhere?
Best regards,
Gerard.
Re: Use of javascript magic hooks
Posted: 2014-06-12 08:53
by a.gneady
Yes it could, the "tablename-dv.js" file. Maybe something like this:
Code: Select all
jQuery(function(){
jQuery('#field1').change(function(){
jQuery('#field2').val('new value');
});
});
In the above code, changing field1 would set field2 to 'new value'.
Re: Use of javascript magic hooks
Posted: 2014-06-13 06:49
by gerardus
Thanks a lot, ahmad. I'll try it asap.
Re: Use of javascript magic hooks
Posted: 2014-06-13 09:08
by gerardus
Ok, here's the result of 1 hour of fumbling with javascript

(simplified a lot for instructive purposes):
// Sets total field to read-only
document.getElementById("total").readOnly = true;
// set event hooks
$('qty').observe('change', qtyOrPriceChanged);
$('price').observe('change', qtyOrPriceChanged);
// hook function
function qtyOrPriceChanged(event) {
calc();
}
// calc function
function calc()
{
var qty = $("qty").value;
var price = $("price").value;
var total = qty * price;
$('total').value = total;
}
It works! (And it reminds me why I like Object pascal

).
BTW, does anybody know if there is a way to get some error message when the javascript is incorrect, instead of nothing happening?
best regards,
Gerard.
Re: Use of javascript magic hooks
Posted: 2014-06-13 12:11
by gerardus
And trickier question: how could i detect a dropdown list (referenced table) changing?
Cheers,
Gerard.
Re: Use of javascript magic hooks
Posted: 2014-06-14 19:54
by a.gneady
BTW, does anybody know if there is a way to get some error message when the javascript is incorrect, instead of nothing happening?
Install Firebug plugin for Firefox and open the console then reload the current page to see if there are any javascript error messages.
how could i detect a dropdown list (referenced table) changing
Lookups use "select2" component. Please refer to the events section of select2 documentation:
http://ivaynberg.github.io/select2/#documentation
Re: Use of javascript magic hooks
Posted: 2014-06-16 08:07
by gerardus
Thx again, Ahmad.
Re: Use of javascript magic hooks
Posted: 2014-06-16 11:20
by gerardus
I'm sorry to bother you again, but I cannot find the select2 component in the loaded page.
Re: Use of javascript magic hooks
Posted: 2014-06-16 21:59
by a.gneady
Use an expression like this:
Code: Select all
jQuery('#fieldname-container').select2('command');
Replace 'fieldname' above with the lookup field name, and "command" with the select2 command you want to execute (as detailed in the select2 documentation)
Re: Use of javascript magic hooks
Posted: 2014-06-17 06:36
by gerardus
Re: Use of javascript magic hooks
Posted: 2016-12-15 16:07
by igimanigi
Hi guys, i have stumbled on this thread and it happens to be something that i am fighting with for about 2 days now. I am trying to get the command for accessing the text of the selected value on the dropdown menu. I am only able to retrieve the ID using the 'val' command. Please help me. What is the command to get text. Also can i have a link to this documentation you speak of.
Re: Use of javascript magic hooks
Posted: 2016-12-18 10:58
by DevGiu
I answered you in the other thread.
Re: Use of javascript magic hooks
Posted: 2017-03-09 07:07
by xbox2007
nice ,but i would like to ask
what if i would like change #field2 in other table .... ( not same table )
#field1 in table name ( AAAA )
#field2 in table Name ( BBBB )
if #field1 change , #field1 change ??????