0

I inherited a YII based web application but I am not really familiar with Yii and don't find the solution yet. So if you can, please help me!

There is a form. In the form there is a dropdown list which get data from a db table. This table contains the name and the price of leases. The dropdown lists only the name.

<?php
    $typeNames = array();
    foreach(LeaseType::model()->findAll() as $lt) {
        $typeNames[$lt->id] = $lt->name;
    }
    ?>
    <?php echo $form->dropDownListControlGroup($model, 'lease_type_id', 
                $typeNames,
                array(
                                    'empty'=>'Válassz!',
                                    'onchange'=>'$("#model-payed").val($("#model-lease_type_id option:selected").text());',
                                    )
                ); ?>

But I need to change the value of a specific input text field with the price of the selected lease.

<?php echo $form->textfield($model,'payed');?>

I can get the name of the lease but I can't set the value of the input for the price of the lease. This field has to be changable based on the customer payed all the price or just partial.

Other problem is that the name and price of the lease in different table than the value needed.

I hope all this are understandable because I am not fluent in English.

Thanks for any help!

1 Answer 1

1

Finally I found the solution, so share it maybe someone can use it.

In the views/_form.php I modified the dropdownlist:

<?php
    echo $form->dropDownListControlGroup($model, 'lease_type_id', $typeNames, array(
    'empty' => 'Válassz!',
    'onchange' => '$("#model_comment").val($("#model_lease_type_id option:selected").$typeNames);',
        //'onchange'=>'if($(this).val() == "no"){("#quantity").val("0"); }'
        )
);
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.