How To Show Value From Other Field Based Ajax?

I was tried to show data based controller. In my form like this :


<?php echo $form->textFieldControlGroup($model,'ACC_CODE',array('span'=>10,'maxlength'=>20,'autocomplete'=>'off','help'=>'Batas Kode 20 karakter',

            'ajax' => array(

                    'type'=>'POST',

                    'url'=>CController::createUrl('OpenReadOnly'),

                    'data'=>array('code_acc'=>'js:this.value'),

                    'success'=>'js:function(data) { $("#umum_acc").val(data);}',

            )

        )); ?>

<?php echo $form->textFieldControlGroup($model,'ACC_UMUM',array('id'=>'umum_acc','span'=>10,'maxlength'=>20,'autocomplete'=>'off')); ?>

<?php echo $form->textFieldControlGroup($model,'ACC_LEVL',array('id'=>'level_acc', 'span'=>3,'maxlength'=>1,'autocomplete'=>'off')); ?>



How to gets value from umum_acc based firstly ACC_CODE is not empty, and use to this value to ACC_LEVEL??

sory for my bad english.

I also try this way, but not working :


<?php echo $form->textFieldControlGroup($model,'ACC_UMUM',array('id'=>'umum_acc','span'=>10,'maxlength'=>20,'autocomplete'=>'off',

            'ajax' => array(

                    'type'=>'POST',

                    'url'=>CController::createUrl('OpenReadOnly2'),

                    'data'=>array('code_acc'=>'js:this.value'),

                    'success'=>'js:function(data) { $("#level_acc").val(data);}',

            ))); ?>

Hello masdib.banget

Please can you share the controller function you’re trying,

As i see in your code, first ajax action also should be prefixed with action in the controller hope you’ve done it, eg-


public function actionOpenReadOnly2(){}

then add it to the accessRules just the function name without prefix


public function accessRules() {

        return array(

            array('allow', // allow all users to perform 'index' and 'view' actions

                'actions' => array('index', 'view', 'OpenReadOnly2'),

                'users' => array('@'),

            ),            

            ),

        );

    }

in the firebug please check wheather ajax triggers and try alerting the data in ajax success

This actionOpenReadOnly2 :


 public function actionOpenReadOnly2() { 

                echo $_POST['umum_acc'];

                Yii::app()->end();

          }

And add rule for this action. But still not work.

And in firebug, actionOpenReadOnly is work well and show code_acc : 11010105, but for action OpenReadOnly2 not listed.

ususally when adding ajax in htmlOptions of an element binded on change function, check your page output by pressing ctrl+u on your page, something like this should be attached to that html element.


jQuery('body').on('change','#element_id',function(){/* check whether your ajax code is here*/})

try whether another change function for the same element binded.

This is result : ctrl+u :


<script type="text/javascript">

/*<![CDATA[*/

jQuery('body').popover({'selector':'a[rel=popover]'});

jQuery('body').tooltip({'selector':'a[rel=tooltip]'});

jQuery(function($) {

jQuery('body').on('change','#Accoumdb_ACC_CODE',function(){jQuery.ajax({'type':'POST','url':'/tpd-baj/master/tabel-perkiraan/OpenReadOnlySatu','data':{'code_acc':this.value},'success':function(data) { $("#umum_acc").val(data); },'cache':false});return false;});

jQuery('body').on('change','#umum_acc',function(){jQuery.ajax({'type':'POST','url':'/tpd-baj/master/tabel-perkiraan/OpenReadOnlyDua','data':{'umum_acc':this.value},'success':function(data) { $("#level_acc").val(data); },'cache':false});return false;});


					if(!window.location.hash)

						jQuery('#Accoumdb_ACC_CODE').focus();

				

});

/*]]>*/

</script>

code looks okay to me, we’ll debug it step by step, Okay first for temporally comment the $(’#umum_acc’) change function where you’ve written it, and then try whether $(’#Accoumdb_ACC_CODE’).change(function(){}) triggers with the right ajax url don’t pass any data just echo die in the controller ajax url action you should be able to see the echoed response in the firebug ajax post response;

Hmm, perfecto.

Yes, its work.

This my revision code :


<?php echo $form->textFieldControlGroup($model,'ACC_CODE',array('span'=>10,'maxlength'=>20,'autocomplete'=>'off','help'=>'Batas Kode 20 karakter',

            'ajax' => array(

                    'type'=>'POST',

                    'url'=>CController::createUrl('OpenReadOnlySatu'),

                    'data'=>array('code_acc'=>'js:this.value'),

                    'success'=>'js:function(data) { $("#Accoumdb_ACC_UMUM").val(data); }',

            )

        )); 

        ?>

        <?php echo $form->textFieldControlGroup($model,'ACC_UMUM',array('id'=>CHtml::activeId($model,'ACC_UMUM'),'span'=>10,'maxlength'=>20,'autocomplete'=>'off',

            'ajax' => array(

                    'type'=>'POST',

                    'url'=>CController::createUrl('OpenReadOnlyDua'),

                    'data'=>array('umum_acc'=>'js:this.value'),

                    'success'=>'js:function(data) { $("#Accoumdb_ACC_LEVL").val(data); }',

            )

        )); ?>

        <?php echo $form->textFieldControlGroup($model,'ACC_LEVL',array('id'=>CHtml::activeId($model,'ACC_LEVL'), 'span'=>3,'maxlength'=>1,'autocomplete'=>'off')); ?>

But, its use ‘tab’ button on keyboard for sent data from ACC_UMUM to ACC_LEVL. Can’t automatic if ACC_UMUM isset or empty?

In firebug :


<script type="text/javascript">

/*<![CDATA[*/

jQuery('body').popover({'selector':'a[rel=popover]'});

jQuery('body').tooltip({'selector':'a[rel=tooltip]'});

jQuery(function($) {

jQuery('body').on('change','#Accoumdb_ACC_CODE',function(){jQuery.ajax({'type':'POST','url':'/tpd-baj/master/tabel-perkiraan/OpenReadOnlySatu','data':{'code_acc':this.value},'success':function(data) { $("#Accoumdb_ACC_UMUM").val(data); },'cache':false});return false;});

jQuery('body').on('change','#Accoumdb_ACC_UMUM',function(){jQuery.ajax({'type':'POST','url':'/tpd-baj/master/tabel-perkiraan/OpenReadOnlyDua','data':{'umum_acc':this.value},'success':function(data) { $("#Accoumdb_ACC_LEVL").val(data); },'cache':false});return false;});


					if(!window.location.hash)

						jQuery('#Accoumdb_ACC_CODE').focus();

				

});

/*]]>*/

</script>

Normally when value changes in the input field change event triggers. i think some javascript library or your very own code might be preventing event key code detection can you write jQuery(’#Accoumdb_ACC_CODE’) test change function or on keypress to this element whather you can get the out put if no values on these events you might have to check you javascripts and libraries.

Hi, Vilo.

Hard to me. Use onkeypress. :o

Other ways. Can I process data to one controller and show procceed data to any element?

Hi masdib.banget

try this code, an alert should trigger every time you type a word then can guarantee that you’re not doing anything with event.keyCode




$cs = $cs = Yii::app()->clientScript;

$cs->registerScript("yourFormName", 

"$('#Accoumdb_ACC_UMUM').keypress(function(){ alert($('#Accoumdb_ACC_UMUM').val())}, CClientScript::POS_READY);"

)



It’s must press and go to ACC_UMUM to generate ACC_LEVL. How to generate all by the one jumping cursor after entry ACC_CODE?