Retrieve Value from selection

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
devedix
Veteran Member
Posts: 30
Joined: 2021-04-20 10:44

Retrieve Value from selection

Post by devedix » 2021-05-12 17:46

Hi all,
I'm following the tutorial on how to retrieve value from selection but it keeps getting the old productID value.
I'm following this code from Ahmed with the Northwind demo.
in order_details-dv.js

Code: Select all

$j(function(){
    
    /** On changing product, retrieve unit price from products table and populate unit price field */
    $j('#ProductID-container').on('change', function(){
        var pid = $j('#ProductID').val();

        if(pid == '{empty_value}'){
            $j('#UnitPrice').val('');
        }else{
            $j.ajax({
                url: 'hooks/ajax-product-price.php?pid=' + pid,
                data: { pid: pid },
                success: function(data){
                    //$j('#UnitPrice').val(data);
                    alert(pid);
                }
            });
            
        }
        // }
    });
});
in ajax-product-price.php

Code: Select all

<?php
    $cuffDir = dirname(__FILE__). '/..';
    include("$cuffDir/defaultLang.php");
    include("$cuffDir/language.php");
    include("$cuffDir/lib.php");
    
    /* grant access to all users who have access to the order_details table */
    $od_from = get_sql_from('order_details');
    if(!$od_from){
        header('HTTP/1.0 401 Unauthorized');
        exit;
    }

    $pid = intval($_REQUEST['pid']);

    $unit_price = sqlValue("select UnitPrice from products where ProductID='{$pid}'");

    echo $unit_price;
?>
But its return the value of the old selection.

Do you guys know what is the problem? Is it because of the Appgini version?
I'm using version 5.95
Regards,
Edix

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Retrieve Value from selection

Post by pbottcher » 2021-05-12 20:18

Hi,

try changing

Code: Select all

   $j('#ProductID-container').on('change', function(){
        var pid = $j('#ProductID').val();
to:

Code: Select all

   $j('#ProductID-container').on('change', function(e){
        var pid = e.added.id;
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

devedix
Veteran Member
Posts: 30
Joined: 2021-04-20 10:44

Re: Retrieve Value from selection

Post by devedix » 2021-05-13 13:04

Hi, pböttcher

Thanks for the help, its works like a charm.
Regards,
Edix

Post Reply