Results 1 to 6 of 6

Thread: Javascript - Onchange

  1. #1
    ff76 is offline Sugar Community Member
    Join Date
    May 2008
    Posts
    96

    Default Javascript - Onchange

    Hi,

    I have this problem.. I have create a custom Module with module builder and I have this field:

    - km
    - cost_km
    - total

    I want to do this calculation when change the field cost_km:

    total = km * cost_km

    I do not know javascript...

    How I can do?

    thank you

  2. #2
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: Javascript - Onchange

    Unfortunately, you'll need to know some php to create a logic hook that does that calculation before_save.

  3. #3
    ff76 is offline Sugar Community Member
    Join Date
    May 2008
    Posts
    96

    Default Re: Javascript - Onchange

    i have create this file logic_hooks.php in the custom folder:

    PHP Code:
    <?php
    // Do not store anything in this file that is not part of the array or the hook version.  This file will    
    // be automatically rebuilt in the future. 
     
    $hook_version 1
    $hook_array = Array(); 
    // position, file, function 
    $hook_array['before_save'] = Array(); 
    $hook_array['before_save'][] = Array(1'calcola_totale''modules/med_Rimborso_Righe/aggiornaRimborsoHook.php','aggiornaRimborsoHook''aggiornaRiga'); 
    ?>
    also I have create this file aggiornaRimborsoHook.php

    PHP Code:
    <?php
    class aggiornaRimborsoHook
    {
      
    // Aggiorno i Rimborsi
      
    function aggiornaRiga(&$bean$event$arguments)
      {
        
    $tbl $bean->table_name;

        
    $id $bean->id;

        
    // calcolo il rimborso 
        
    $rimborso $bean->costo_km $bean->km;
        
        
    $q "UPDATE med_rimborso_righe md SET md.rimborso_km =  $rimborso WHERE md.id = '$id'";
        
    $bean->db->query($q);
      }
    }
    ?>
    The problem is that: the field rimborso_km is not updated..

    Why ?
    Last edited by ff76; 2008-12-04 at 07:31 AM.

  4. #4
    ff76 is offline Sugar Community Member
    Join Date
    May 2008
    Posts
    96

    Default Re: Javascript - Onchange

    Quote Originally Posted by ff76 View Post
    i have create this file logic_hooks.php in the custom folder:

    PHP Code:
    <?php
    // Do not store anything in this file that is not part of the array or the hook version.  This file will    
    // be automatically rebuilt in the future. 
     
    $hook_version 1
    $hook_array = Array(); 
    // position, file, function 
    $hook_array['before_save'] = Array(); 
    $hook_array['before_save'][] = Array(1'calcola_totale''modules/med_Rimborso_Righe/aggiornaRimborsoHook.php','aggiornaRimborsoHook''aggiornaRiga'); 
    ?>
    also I have create this file aggiornaRimborsoHook.php

    PHP Code:
    <?php
    class aggiornaRimborsoHook
    {
      
    // Aggiorno i Rimborsi
      
    function aggiornaRiga(&$bean$event$arguments)
      {
        
    $tbl $bean->table_name;

        
    $id $bean->id;

        
    // calcolo il rimborso 
        
    $rimborso $bean->costo_km $bean->km;
        
        
    $q "UPDATE med_rimborso_righe md SET md.rimborso_km =  $rimborso WHERE md.id = '$id'";
        
    $bean->db->query($q);
      }
    }
    ?>
    The problem is that: the field rimborso_km is not updated..

    Why ?
    I resolved...

    But how to use yhe function handleRedirect ?

  5. #5
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: Javascript - Onchange

    Nicely done! Instead of using SQL in your logic hook you should be able to just set the bean attribute:

    PHP Code:
    <?php
    class aggiornaRimborsoHook
    {
      
    // Aggiorno i Rimborsi
      
    function aggiornaRiga(&$bean$event$arguments)
      {
        
    // calcolo il rimborso 
        
    $bean->rimborso $bean->costo_km $bean->km;  

      }
    }
    ?>
    A now that it is set it should save.

  6. #6
    tepepa is offline Member
    Join Date
    Nov 2010
    Posts
    19

    Default Re: Javascript - Onchange

    Quote Originally Posted by ff76 View Post
    I resolved...

    But how to use yhe function handleRedirect ?
    Can you please post the solution?
    Thank you

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Javascript onchange
    By danrweki in forum Developer Help
    Replies: 13
    Last Post: 2012-05-03, 09:52 AM
  2. populate multiple fields with an onchange event
    By danrweki in forum Developer Help
    Replies: 5
    Last Post: 2008-08-08, 12:38 PM
  3. Javascript onchange not working
    By danrweki in forum Help
    Replies: 0
    Last Post: 2008-07-31, 12:24 PM
  4. adding onchange to Opp.sales_stage
    By markiewicz in forum Help
    Replies: 1
    Last Post: 2008-05-13, 09:08 PM
  5. javascript
    By rohandey in forum Developer Help
    Replies: 2
    Last Post: 2006-05-26, 06:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •