Oiram
(Oiramgloria)
July 24, 2014, 7:55pm
1
I’m new in yii
I need sum 2 values since textField1 and textField2 and deposit in textFieldResul with onchange Event
This is my code…
<?php echo $form->labelEx($model,‘value1’); ?>
<?php echo $form->textField($model,‘value1’,array(‘value’=>0));
<?php echo $form->error($model,‘value1’); ?>
<?php echo $form->labelEx($model,‘value2’); ?>
<?php echo $form->textField($model,‘value2’,array(‘value’=>0));
<?php echo $form->error($model,‘value2’); ?>
<?php echo $form->labelEx($model,‘result’); ?>
<?php echo $form->textField($model,‘result’,array(‘value’=>0));
<?php echo $form->error($model,‘result’); ?>
Can U please explain this a bit more? If I got U right, U want ‘result’ field to be populated with sum of ‘value1’ nad ‘value2’ fields?
Oiram
(Oiramgloria)
July 24, 2014, 8:14pm
3
Thanks Newbie, i need insert one value in textField1 also in textField2 and immediately get the sum of (textField1+textField2) in the textField Result.
This looks like js or jquery task more than Yii. Anyway U can do it on page with jQuery, something like:
// attach event on both fields
$(‘document’)on(‘change’ ‘#field1ID ’ function() {
populateResult();
})
$(‘document’)on(‘change’ ‘#field2ID ’ function() {
populateResult();
})
// function that will collect values from both fields and populate result field
function populateResult()
{
var val1 = if($(’#field1ID ’).val()) ? $(’#field1ID ’).val() : 0;
var val2 = if($(’#field2ID ’).val()) ? $(’#field2ID ’).val() : 0;
// calculate
var sum = (val1 + val2)
// populate result field
$(’#resultFieldID ’).val(sum);
}
U will probably need to clean up this code in order to get full functioanlity
Oiram
(Oiramgloria)
July 28, 2014, 6:19pm
5
Sorry Newbie which is the correct way of attach event in the textFiles could you give me one example please…