how to add ajax method and calculation
- Single Page
Posted 11 September 2014 - 12:20 PM
Posted 14 September 2014 - 08:38 AM
Well my friend - what i understand loking at this form of yours - u want to generate the vlue of the field mentioned abouve at runtime based on the user selection of values. If that is so - what you need to do is write an action in controller that accepts a set of values (of definitions) that u wana send across and it returns u the value.
Second thing that you need to do is write a js file which will have a hook to (field - u need to select the field on whose change the value here will get changed) on change event - it calls to a function which makes an ajax call to the above action as described
the value it returns - (on success) - it gets displayed in the text field. - once the js is built - u need to add the same to the crud using set_js functionality.
PS - read the solution 3-4 times if not understood in 1 attempt - the solution provided is a clear need for the outcome expected. Sorry as wouldnt be able to share u coded solution for the same.
Happy GCing :)
Posted 17 September 2014 - 10:45 AM
i can't understand sir
plz some small example code for me plz help. i am first time use grocery crud
Posted 19 September 2014 - 07:55 AM
Well my friend - what i understand loking at this form of yours - u want to generate the vlue of the field mentioned abouve at runtime based on the user selection of values. If that is so - what you need to do is write an action in controller that accepts a set of values (of definitions) that u wana send across and it returns u the value.
Second thing that you need to do is write a js file which will have a hook to (field - u need to select the field on whose change the value here will get changed) on change event - it calls to a function which makes an ajax call to the above action as described
the value it returns - (on success) - it gets displayed in the text field. - once the js is built - u need to add the same to the crud using set_js functionality.
PS - read the solution 3-4 times if not understood in 1 attempt - the solution provided is a clear need for the outcome expected. Sorry as wouldnt be able to share u coded solution for the same.
Happy GCing :)
thanx Amit
yes i can do it successfully
Posted 19 September 2014 - 10:41 AM
Well done... Happy to help you out :)
Happy GCing :)
Posted 07 July 2015 - 16:59 PM
thanx Amit
yes i can do it successfully
Great !!!
Coul'd you explain or better : post/show your final code. I need exatly the same fonctionnality.
I understand well your first post with your code, it looks like coul'd help my need.
I see (I read a lot of time Amit solution) what to do, but it's a bit short for me, newbee with codeIgniter and GroceryCrud :)
Thanks a lot
Lionel
Posted 16 January 2017 - 10:27 AM
nice to meet you all, im new using grocerycrud
i have a problem with same case ...
i was create simple JS file then set_js to template add.php ....... it's showing alert if i just put alert('') in my_js.js
then i change to
$(".sewa_dp").change(function(){ alert(''); })
my view using callback_field to create ID
$crud->callback_field('sewa_dp', function () { return 'Rp. <input type="text" maxlength="20" value="0" name="sewa_dp" id="sewa_dp"> '; });
when i change value sewa_dp .. its dont show alert for that ... anyone can help me ???
Posted 18 January 2017 - 02:00 AM
Hi HACK,
What you are trying to do is .. make a call on change .. of a class ..
Your code ...... $(".sewa_dp").change(function(){ ....
There.. i may be able to work successfully with the pre-generated code. You have hooked the js call on the class sewa_dp
then when u doing a callback - you overriding the output generated earlier by the GC library and getting your own code.. if u see in there.. there is noclass sewa_dp available
This is the reason - you are not getting an alert ...