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;
 }
}
2 Answers 2
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 happenuser31071– user310712015年10月01日 11:21:53 +00:00Commented Oct 1, 2015 at 11:21
- 
 did you add your field #ids in this function?Qaisar Satti– Qaisar Satti2015年10月01日 11:25:52 +00:00Commented Oct 1, 2015 at 11:25
- 
 Yup. I have created class comment.php in my model folder and integrated my selectbox id in it.user31071– user310712015年10月01日 11:37:33 +00:00Commented Oct 1, 2015 at 11:37
- 
 did it try alert in function it is working or not?Qaisar Satti– Qaisar Satti2015年10月01日 11:42:05 +00:00Commented Oct 1, 2015 at 11:42
- 
 I tried it but no luck. I believes it doesn't get calleduser31071– user310712015年10月01日 11:43:40 +00:00Commented Oct 1, 2015 at 11:43
<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>
Explore related questions
See similar questions with these tags.