3

I have added select option SFTP host with values production, sandbox in my system.xml file of custom extenstion. There is one text field SFTP port in system.xml. I want to set the text field value on change of selection.

If I select production , then port value = 22 If I select sandbox , then port value = 21

<ftphost translate="label">
<label>SFTP host</label>
<frontend_type>select</frontend_type>
<source_model>gb/system_config_source_sftp</source_model>
<sort_order>60</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</ftphost>
<ftpport translate="label">
 <label>SFTP port</label>
 <frontend_type>text</frontend_type>
 <sort_order>70</sort_order>
 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>
 </ftpport>

new system.xml

<liveenvironment translate="label">
                            <label>Live environment</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                             <comment><model>gb_gbgsp/system_config_source_sftpcomment</model>
     </comment>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </liveenvironment>

comment.php

<?php 
class gb_gbgsp_Model_Adminhtml_System_Config_Source_Sftpcomment extends Mage_Core_Model_Config_Data
{
    public function getCommentText(Mage_Core_Model_Config_Element $element, $currentValue)
    {

    $result = "<script type='text/javascript'>    

            function init_comment()
            {

                $('#carriers_gbgsp_liveenvironment').observe('change', function(){
                    var field_value = $('#carriers_gbgsp_liveenvironment').getValue();
                    alert(field_value);
                });
            }
            document.observe('dom:loaded', function(){init_comment();});
            </script>";

        return $result;
    }
}
0

you can add your js through comment model

<ftphost translate="label">
    <label>SFTP host</label>
    <frontend_type>select</frontend_type>
    <source_model>gb/system_config_source_sftp</source_model>
    <comment> <![CDATA[<script type='text/javascript'>    

        function init_comment()
        {

            $('yourslelectid').observe('change', function(){
                var field_value = $('yourslelectid').getValue();
                //add your condition here
            });
        }
        document.observe('dom:loaded', function(){init_comment();});
        </script>]]
     </comment>
    <sort_order>60</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
    </ftphost>
  • I tried this but nothing happen – user31071 Oct 1 '15 at 11:21
  • did you add your field #ids in this function? – Qaisar Satti Oct 1 '15 at 11:25
  • Yup. I have created class comment.php in my model folder and integrated my selectbox id in it. – user31071 Oct 1 '15 at 11:37
  • did it try alert in function it is working or not? – Qaisar Satti Oct 1 '15 at 11:42
  • I tried it but no luck. I believes it doesn't get called – user31071 Oct 1 '15 at 11:43
0
<liveenvironment translate="label">
                            <label>Live environment</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
    <comment><![CDATA[
                             <script type='text/javascript'>    

            function init_comment()
            {

                $('carriers_gbgsp_liveenvironment').observe('change', function(){
                    var field_value = $('carriers_gbgsp_liveenvironment').getValue();
                    alert(field_value);
                });
            }
            document.observe('dom:loaded', function(){init_comment();});
            </script>
                             ]]>  </comment>
    <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </liveenvironment>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.