Yii Framework Forum: menjumlah kan 2 input - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

menjumlah kan 2 input Rate Topic: ***** 1 Votes

#1 User is offline   kokoadi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 03-December 08

Posted 21 March 2012 - 11:34 AM

Bagaimana cara menjumlahkan 2 input CMaskedTextField dan hasilnya d munculkan d labelEx. Dg sistem.completed pd cmasked. Mohon bantuan rekan2
0

#2 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 21 March 2012 - 10:39 PM

View Postkokoadi, on 21 March 2012 - 11:34 AM, said:

Bagaimana cara menjumlahkan 2 input CMaskedTextField dan hasilnya d munculkan d labelEx. Dg sistem.completed pd cmasked. Mohon bantuan rekan2


maksudnya kaya gimana ya gan?
belajar itu mudah..
0

#3 User is offline   kokoadi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 03-December 08

Posted 22 March 2012 - 12:05 AM

contohnya kita punya view spt ini:

$this->widget('CMaskedTextField',array(
    'model'=>$model,
    'attribute'=>'input1',
    'name'=>'input1',
    'mask'=>'9.99',    
    'htmlOptions'=>array(
        'style'=>'width:80px;'
    ),
));
$this->widget('CMaskedTextField',array(
    'model'=>$model,
    'attribute'=>'input2',
    'name'=>'input2',
    'mask'=>'9.99',
    'completed'=>'???',
    'htmlOptions'=>array(
        'style'=>'width:80px;'
    ),
));

$form->labelEx($model,'hasil'); 


nah user menginputkan datanya di input1 trus kita tambahkan ke input2 hasilnya di label "hasil" tapi menggunakan event jika input2 selesai di inputkan lnagsung di proses tanpa menggunakan tombol submit.
0

#4 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 22 March 2012 - 02:10 AM

coba pake ajax onchange aja di htmlOptionnya....
kayanya hampir sama kaya ini. coba ini.
belajar itu mudah..
0

#5 User is offline   kokoadi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 03-December 08

Posted 26 March 2012 - 09:19 AM

[SOLVE] using JQuery event, mengurangi ajax :D biar ngak lama requestnya d server :D
0

#6 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 26 March 2012 - 10:24 PM

View Postkokoadi, on 26 March 2012 - 09:19 AM, said:

[SOLVE] using JQuery event, mengurangi ajax :D biar ngak lama requestnya d server :D

judulnya ganti jadi solved gan, trus codenya di taro juga, biar kalo ada orang yang punya masalah sama bisa kebantu..
just share..
belajar itu mudah..
0

#7 User is offline   kokoadi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 03-December 08

Posted 29 March 2012 - 10:19 PM

$jsRata  = "function(){";								
$jsRata .= "var hitung;";
$jsRata .= "hitung = (parseFloat($('#".CHtml::activeId($model,'kls41_casiswa')."').val())+ parseFloat($('#".CHtml::activeId($model,'kls42_casiswa')."').val());";
$jsRata .= "hitung = new String(hitung).valueOf();}";
$jsRata .= "$('#".CHtml::activeId($model,'ratakls_casiswa')."').val(new String(hitung).valueOf().substring(0,4));}";

$this->widget('CMaskedTextField', array(
 'model'=>$model, 'attribute'=> 'kls41_casiswa', 'mask'=>9.99,
 'completed'=>$jsRata,
 'htmlOptions'=>array(
   'style'=>'width:35px;',											
 )
));


$this->widget('CMaskedTextField', array(
 'model'=>$model, 'attribute'=> 'kls41_casiswa', 'mask'=>9.99,
 'completed'=>$jsRata,
 'htmlOptions'=>array(
   'style'=>'width:35px;',											
 )
));

echo $form->textField($model,'ratakls_casiswa', array('readOnly'=>'readOnly',));

0

#8 User is offline   kanra 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 27-June 13

Posted 27 June 2013 - 01:06 PM

View Postkokoadi, on 29 March 2012 - 10:19 PM, said:

$jsRata  = "function(){";								
$jsRata .= "var hitung;";
$jsRata .= "hitung = (parseFloat($('#".CHtml::activeId($model,'kls41_casiswa')."').val())+ parseFloat($('#".CHtml::activeId($model,'kls42_casiswa')."').val());";
$jsRata .= "hitung = new String(hitung).valueOf();}";
$jsRata .= "$('#".CHtml::activeId($model,'ratakls_casiswa')."').val(new String(hitung).valueOf().substring(0,4));}";

$this->widget('CMaskedTextField', array(
 'model'=>$model, 'attribute'=> 'kls41_casiswa', 'mask'=>9.99,
 'completed'=>$jsRata,
 'htmlOptions'=>array(
   'style'=>'width:35px;',											
 )
));


$this->widget('CMaskedTextField', array(
 'model'=>$model, 'attribute'=> 'kls41_casiswa', 'mask'=>9.99,
 'completed'=>$jsRata,
 'htmlOptions'=>array(
   'style'=>'width:35px;',											
 )
));

echo $form->textField($model,'ratakls_casiswa', array('readOnly'=>'readOnly',));



mastah mau nanya itu code-nya di taruh di dalam form view-nya?
apa perlu kode tambahan di controler atau modelnya?
satu lagi, dua data yang diinputkan itu masuk ke dalam tabel database juga ndak?kalau tidak bagaimana supaya bisa masuk ke database?

maaf pertanyaannya banyak,saya masih nubie ;D
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users