Results 1 to 8 of 8

Thread: onchange event for dropdown

  1. #1
    vijay9948 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    56

    Default onchange event for dropdown

    Hi everyone,

    Am using Sugarcrm CE 5.1 edition

    I have one dropdown list which contains country names

    So my requirement is once i click on any country name in dropdown list the state should be populated in other text field

    How can i acheive this????

    I kindly request u all to give me the code for this

    pls
    pls
    pls

  2. #2
    daniel.passarini's Avatar
    daniel.passarini is offline Sugar Community Member
    Join Date
    Apr 2006
    Location
    São Paulo - SP / Brasil
    Posts
    80

    Default Re: onchange event for dropdown

    your editviewdefs file should have something like this:
    PHP Code:
                'name' => 'country',
                
    'label' => 'LBL_COUNTRY',
                
    'displayParams'=>array('javascript'=>'onchange="fillOtherField()"'), 
    Daniel de Carvalho Passarini

    "Fascinating" - Dr. Spock

  3. #3
    vijay9948 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    56

    Default Re: onchange event for dropdown

    Thank u for ur reply

    But my problem is Where to write that function fillrequired_field()

    wat i mean to say is in which file i want to add this function

    pls give me sample code
    pl
    pls

  4. #4
    daniel.passarini's Avatar
    daniel.passarini is offline Sugar Community Member
    Join Date
    Apr 2006
    Location
    São Paulo - SP / Brasil
    Posts
    80

    Default Re: onchange event for dropdown

    The safest option is to create a view.edit.php in custom/modules/SystemModule/views/ (for the default modules)
    ou in modules/YourNewModule/views/ (for your custom modules)
    in this file you put:
    PHP Code:
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    require_once(
    'include/MVC/View/views/view.edit.php');

    class 
    YourModuleViewEdit extends ViewEdit{
        
        function 
    YourModuleViewEdit() {
            
    parent::ViewEdit();
        }
        
        function 
    display(){    
                   
    /// HERE IS THE FILE WHERE YOU CAN PUT YOU JS FUCTIONS
            
    echo '<script type="text/javascript" src="custom/include/javascript/you_js_utils.js"></script>';
            
            
    parent::display();
        }

    I hope it helps
    Daniel de Carvalho Passarini

    "Fascinating" - Dr. Spock

  5. #5
    vijay9948 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    56

    Default Re: onchange event for dropdown

    Quote Originally Posted by daniel.passarini View Post
    The safest option is to create a view.edit.php in custom/modules/SystemModule/views/ (for the default modules)
    ou in modules/YourNewModule/views/ (for your custom modules)
    in this file you put:
    PHP Code:
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    require_once(
    'include/MVC/View/views/view.edit.php');

    class 
    YourModuleViewEdit extends ViewEdit{
        
        function 
    YourModuleViewEdit() {
            
    parent::ViewEdit();
        }
        
        function 
    display(){    
                   
    /// HERE IS THE FILE WHERE YOU CAN PUT YOU JS FUCTIONS
            
    echo '<script type="text/javascript" src="custom/include/javascript/you_js_utils.js"></script>';
            
            
    parent::display();
        }

    I hope it helps



    Thank u for ur reply

    Whatever U said above i have done u can see below for the code


    modules/ss01_TaxExemptions/views/view.edit.php

    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    require_once('include/MVC/View/views/view.edit.php');

    class ss01_TaxExemptionsViewEdit extends ViewEdit{

    function ss01_TaxExemptionsViewEdit() {
    parent::ViewEdit();
    }

    function display(){
    /// HERE IS THE FILE WHERE YOU CAN PUT YOU JS FUCTIONS
    echo '<script type="text/javascript" src="custom/include/javascript/you_js_utils.js"></script>';

    parent::display();
    }
    }
    ?>
    array (
    'name' => 'status',
    'label' => 'LBL_STATUS',
    'displayParams' =>
    array (
    'javascript' => 'onchange="vijay()"',
    ),
    ),
    1 =>
    array (
    'name' => 'exemptions',
    'label' => 'LBL_EXEMPTIONS',
    ),


    custom/include/javascript/you_js_utils.js
    function vijay()
    {
    document.getElementsByName(\'exemptions\').value=" vijaybhaskar";
    }


    pls give me the correct js code and where to include those js file

    pls
    pls
    pls

  6. #6
    Mithun's Avatar
    Mithun is offline A Prolific Poster
    Join Date
    Mar 2009
    Location
    India
    Posts
    236

    Default Re: onchange event for dropdown

    Quote Originally Posted by daniel.passarini View Post
    The safest option is to create a view.edit.php in custom/modules/SystemModule/views/ (for the default modules)
    ou in modules/YourNewModule/views/ (for your custom modules)
    in this file you put:
    PHP Code:
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    require_once(
    'include/MVC/View/views/view.edit.php');

    class 
    YourModuleViewEdit extends ViewEdit{
        
        function 
    YourModuleViewEdit() {
            
    parent::ViewEdit();
        }
        
        function 
    display(){    
                   
    /// HERE IS THE FILE WHERE YOU CAN PUT YOU JS FUCTIONS
            
    echo '<script type="text/javascript" src="custom/include/javascript/you_js_utils.js"></script>';
            
            
    parent::display();
        }

    I hope it helps
    Thank you daniel
    Mithun P Sreedharan
    ITFlux Inc
    38030 Stenhammer Dr
    Fremont
    CA, USA - 94536
    Phone : (510)-792-8897
    Fax : (408)-877-1588
    For further queries mail to mithun@itflux.com

  7. #7
    christianknoll's Avatar
    christianknoll is offline Sugar Community Member
    Join Date
    Nov 2008
    Location
    Vienna
    Posts
    939

    Default Re: onchange event for dropdown

    Daniel,

    wouldn't it be easier to use the javascript or include property in the metadata of the view? Also allows you to do such things if the view is already redefined.

    christian.

    Quote Originally Posted by daniel.passarini View Post
    The safest option is to create a view.edit.php in custom/modules/SystemModule/views/ (for the default modules)
    ou in modules/YourNewModule/views/ (for your custom modules)
    in this file you put:
    PHP Code:
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    require_once(
    'include/MVC/View/views/view.edit.php');

    class 
    YourModuleViewEdit extends ViewEdit{
        
        function 
    YourModuleViewEdit() {
            
    parent::ViewEdit();
        }
        
        function 
    display(){    
                   
    /// HERE IS THE FILE WHERE YOU CAN PUT YOU JS FUCTIONS
            
    echo '<script type="text/javascript" src="custom/include/javascript/you_js_utils.js"></script>';
            
            
    parent::display();
        }

    I hope it helps

  8. #8
    shamimwilson is offline Sugar Community Member
    Join Date
    Mar 2009
    Location
    Banglore India
    Posts
    235

    Default Re: onchange event for dropdown

    Quote Originally Posted by vijay9948 View Post
    Thank u for ur reply

    Whatever U said above i have done u can see below for the code


    modules/ss01_TaxExemptions/views/view.edit.php

    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    require_once('include/MVC/View/views/view.edit.php');

    class ss01_TaxExemptionsViewEdit extends ViewEdit{

    function ss01_TaxExemptionsViewEdit() {
    parent::ViewEdit();
    }

    function display(){
    /// HERE IS THE FILE WHERE YOU CAN PUT YOU JS FUCTIONS
    echo '<script type="text/javascript" src="custom/include/javascript/you_js_utils.js"></script>';

    parent::display();
    }
    }
    ?>
    array (
    'name' => 'status',
    'label' => 'LBL_STATUS',
    'displayParams' =>
    array (
    'javascript' => 'onchange="vijay()"',
    ),
    ),
    1 =>
    array (
    'name' => 'exemptions',
    'label' => 'LBL_EXEMPTIONS',
    ),


    custom/include/javascript/you_js_utils.js
    function vijay()
    {
    document.getElementsByName(\'exemptions\').value=" vijaybhaskar";
    }


    pls give me the correct js code and where to include those js file

    pls
    pls
    pls

    Hi Vijay,

    I did it in the following way.
    I did it in the Accounts module for the "Account Type" and ownership
    go to custom/module/Accounts/metadata
    Then in the editviewdefs.php
    add the following bold line in account_type
    'name' => 'account_type',
    'label' => 'LBL_TYPE',
    'displayParams'=>array('javascript'=>'onchange="dy namicfill1()"')

    Then in the same editviewdefs.php file add the bold line:
    'includes' =>
    array (
    0 =>
    array (
    'file' => 'modules/Accounts/Account.js',
    'file' => 'custom/modules/Accounts/customfile.js',
    ),


    Then add the customfile.js in the custom/modules/Accounts with the following codes

    function dynamicfill1()
    {
    if(document.getElementById('account_type').value =='Analyst')
    {
    document.getElementById('ownership').value='alpha' ;
    }

    if(document.getElementById('account_type').value =='Customer')
    {
    document.getElementById('ownership').value='Beta';
    }
    if(document.getElementById('account_type').value =='Press')
    {
    document.getElementById('ownership').value='Gama';
    }
    if(document.getElementById('account_type').value =='Partner')
    {
    document.getElementById('ownership').value='Zeta';
    }
    }

    The procedure is that when you select account_type=Analyst then alpha will be added in the ownership field similarly if you press Customer in the account type then Beta will be printed in the ownership field
    ShamimWilson
    shamim.797@gmail.com.

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. Javascript - Onchange
    By ff76 in forum Developer Help
    Replies: 5
    Last Post: 2010-11-05, 10:28 PM
  3. onchange event for dropdown list
    By vijay9948 in forum Developer Help
    Replies: 3
    Last Post: 2009-04-18, 10:42 AM
  4. onchange event for dropdown list
    By vijay9948 in forum Developer Tutorials
    Replies: 0
    Last Post: 2009-01-16, 02:57 AM
  5. populate multiple fields with an onchange event
    By danrweki in forum Developer Help
    Replies: 5
    Last Post: 2008-08-08, 12:38 PM

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
  •