As a newbie with nuBuilder Forte, I created a form with a subform. The form contains a customer field, the subform contains rows with a zip-code, weight and price.
When the zipcode or the weight is changed, I need to fetch the matching price from the database (some matrix which defines the prices).
In the (javascript) onchange-event of the zip-code and weight fields, i have managed to fetch the values of the customerId, weight and zipCode.
Also I defined the query which has to be run and returns the price.
But I have no clue how to proceed from JavaScript to PHP and actually run this query and return the value so I can update the value field.
Any tips/suggestions on this? Or is there a better approach?
Welcome to the nuBuilder Forums!
Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.
Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.
Run query from javascript
-
- nuBuilder Team
- Posts: 4562
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 76 times
- Been thanked: 528 times
- Contact:
Re: Run query from javascript
Hi and welcome to nuBuilder !
Declare this function in your form's Custom Code. Replace sub_zip, sub_weight, sub_price with your column IDs.
In the JS onchange-events of the zip-code and weight field, call:
Last but not least, create a (Tab Builders ->) Procedure with the Code get_price:
Declare this function in your form's Custom Code. Replace sub_zip, sub_weight, sub_price with your column IDs.
Code: Select all
function subformChanged(event) {
var id = event.target.id;
zipVal = nuSubformRowObject(id, 'sub_zip').val();
weightVal = nuSubformRowObject(id, 'sub_weight').val();
priceId = nuSubformRowObject(id, 'sub_price').attr('id');
nuRunPHPHiddenWithParams('get_price', 'param', {zip: zipVal, weight: weightVal, price_id: priceId}, 0);
}
Code: Select all
subformChanged(event);
Code: Select all
$param = json_decode(base64_decode('#param#')); // retrieve the parameters
$zip = $param->zip;
$weight = $param->weight;
$priceId = $param->price_id;
// Retrieve the price here ...
// $price = .....
// Change the price:
$js = " $('#$priceId').val('$price').change(); ";
nuJavascriptCallback($js);
You do not have the required permissions to view the files attached to this post.
-
- Posts: 4
- Joined: Tue Apr 06, 2021 11:11 pm
-
- nuBuilder Team
- Posts: 4562
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 76 times
- Been thanked: 528 times
- Contact: