Page 1 of 1

Retrieve Value from selection

Posted: 2021-05-12 17:46
by devedix
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

Re: Retrieve Value from selection

Posted: 2021-05-12 20:18
by pbottcher
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;

Re: Retrieve Value from selection

Posted: 2021-05-13 13:04
by devedix
Hi, pböttcher

Thanks for the help, its works like a charm.