adding the values of two different textboxes and displaying the result in the third textbox.

[color=#333333][font=-apple-system, BlinkMacSystemFont,]Hello Everyone,[/font][/color]

[color=#333333][font=-apple-system, BlinkMacSystemFont,]I am new to YII framework and i am trying to learn it. I got stuck at a point need your Help![/font][/color]

[color=#333333][font=-apple-system, BlinkMacSystemFont,]My problem is:[/font][/color]

[color=#333333][font=-apple-system, BlinkMacSystemFont,]adding the values of two different textboxes and displaying the result in the third textbox.[/font][/color]

[color=#333333][font=-apple-system, BlinkMacSystemFont,]ihave written a code for this but seems there is some error on that, its not executing…Plz Help[/font][/color]

If your values are values from a table you could do a function in your Model to calculate the resulting value and display it in the GridView for example.

If the values are being added in a form and you want to calculate a third value "on the fly" you could use some JS.

Basically you add your JS code block at the bottom of your page, something like:


$script = <<< JS

$('#yourForm-yourElement').on('change', function() {

// do the operations





Thank you…so much…I was stuck on this from a long time…

great work man…thanks a lot…

In most cases, using ‘registerJs()’ is not necessary and should be avoided where possible. Why have PHP waste any time or resources printing out JavaScript to the page? Sometimes you do need advanced calculations, and it is appropriate. Usually when you can’t handle the JS any other way. You could have it print values on the page, and your JS function loads those values from them, but you don’t need all your JS printed by Yii. You could even have jQuery fetching from a simple API which returns JSON, for passing custom information to the frontend.

Simply have a ‘/web/js/script.js’ or something similar. In it, your jQuery document ready, and place your ‘onChange()’ detection in there. As you go along, place any other JS or jQuery in it.

Not ALL of your files have to be handled by the asset manager…