Hello i´m new in yii i have the next code for sum two values:
My problem is if a set the property ‘name’ in the textField the Form send null values to the database please help !!!
<?php echo $form->textField($model,‘var1’,array(‘value’=>0, ‘name’=>‘var1’,‘onChange’=>‘js:sum()’));?>
<?php echo $form->error($model,‘var1’); ?>
<?php echo $form->textField($model,‘var2’,array(‘value’=>0, ‘name’=>‘var2’,‘onChange’=>‘js:sum()’));?>
<?php echo $form->error($model,‘var2’); ?>
<script>
function sum(){
var num1 = parseInt(document.getElementById('total_Pzas_Ok1').value);
var num2 = parseInt(document.getElementById('total_Pzas_NO_Ok').value);
var result = num1 + num2;
if (result < 0){
document.getElementById('val').value = 0;
}else{
document.getElementById('val').value = result;
}
}
</script>