No announcement yet.

AJAX on chenge doesn't work

  • Filter
  • Time
  • Show
Clear All
new posts

  • AJAX on chenge doesn't work

    Hi I hve a field called name_code with text autocomplete that use this sql sentence

    SELECT code, name 
    FROM products 
    ORDER BY name
    and this code on ajax on chenge event

    $codigo = {name_code};
     * Check for an existing record
    // SQL statement parameters
    $check_table = 'products';    // Table name
    $check_where = "name = '". $codigo . "'"; // Where clause
    // Check for record
    $check_sql = 'SELECT *'
       . ' FROM '  . $check_table
       . ' WHERE ' . $check_where;
    sc_select(dataset, $check_sql);
    if (false == {dataset})
        // Error while accessing database
    elseif ({dataset}->EOF)
     * Display a message after an AJAX call
    // Javascript message parameters
    $javascript_title   = 'Error';       // Javascript message title
    $javascript_message = 'El producto ingresado no existe!!';  // Javascript message contents
    // Display javascript message
    sc_ajax_message($javascript_message, $javascript_title);
        sc_lookup(dataset,"select price from products 
                       WHERE name = '{name_code}'");
        {unitprice} = {dataset}[0][0];
        {unitprice} = 0;

    Until now all good, the list of codes appears, and if I change the code by clicking in some of the code options, the price was changed.

    But, If I don't choose one of the options and I wirte a bad code, nothig happens, no message appears and if I write a correct ode, but no by clicking with the mouse, just writing, nothing happens either, the price doesn't change.

    What I doing wrong??

    Thanks in advance,


  • #2
    If you don't choose one of the options the ajax trigger on the field will not fire. One way of solving this is to set some additional (and duplicate) checks in the onvalidate. You want to be sure that the data which is send to your database is valid. To prevent cripple browsers etc. you can only be sure of testing the values before action which needs to be done in the onvalidate event. The only drawback is that you might loose the other entered fieldvalues and the user needs to fill the full form again.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development /