Auto Fiil Textfield

hi…

please help me bro n sis

i have problem, i want to show data from textfield with auto.

so here the code




<div class="row">

        <?php echo $form->labelEx($model, 'price'); ?> /// fill the text field with some data type int

        <?php echo $form->textField($model, 'price', array('size' => 25, 'maxlength' => 25)); ?>

        <?php echo $form->error($model, 'price'); ?>

    </div>


    <div class="row">

        <?php echo $form->labelEx($model, 'quantity'); ?> /// fill the text field with some data type int

        <?php echo $form->textField($model, 'quantity', array('size' => 25, 'maxlength' => 25)); ?>

        <?php echo $form->error($model, 'quantity'); ?>

    </div>


   //if price n quantity fill so total will appear data from 2 model

   // total = price * quantity

    <div class="row">

        <?php echo $form->labelEx($model, 'total'); ?> 

        <?php echo $form->textField($model, 'total'); ?>

        <?php echo $form->error($model, 'total'); ?>

    </div>



please help me,need fast response n solve

You can just create a getTotal method in your model, which returns price * quantity.

can you give me some code for solve that, because i don’t know javascript ?? pleaseee :D

In your model. You’ll use PHP there :)

please give me some xample because i’m very newbie in yii…

If you don’t know what a model is, you should really read the guide before proceeding.

Also, I made The complete beginner’s study guide for the Yii Framework, which can help you.

thats not answer my question, but thanks for help

Hi Guys i was wrote this code in my model :




 public function getprice($price,$quantity){

            return  $price * $quantity;

        }



and in _form




    <div class="row">

<?php echo $form->labelEx($model, 'price'); ?>

        <?php echo $form->textField($model, 'price', array('size' => 25, 'maxlength' => 25,)); ?>

        <?php echo $form->error($model, 'price'); ?>

    </div>


    <div class="row">

<?php echo $form->labelEx($model, 'quantity'); ?>

        <?php echo $form->textField($model, 'quantity', array('size' => 25, 'maxlength' => 25,'onChange'=>$model->getprice($model->price, $model->quantity))); ?>

        <?php echo $form->error($model, 'quantity'); ?>

    </div>

    

    <div class="row">

<?php echo $form->labelEx($model, 'total'); ?>

        <?php echo $form->textField($model, 'total', array('value' => $model->getprice($model->price, $model->quantity))); ?>

        <?php echo $form->error($model, 'total'); ?>

    </div>




its work but i when i finish sumbit textfield quantity so textfield total will filled with value from method getprice automatic…please help me

Hi,

First, you may want to rename your "getprice" method to "getTotal".

If you just want to have the total filled in automatically to be displayed to the user, you don’t need the new method or even to have an input field.

Just create a span to hold the total:




<div class="row">

  <span id="total">Total: $ <span id="value"></span></span>

</div>



And use Javascript to fill it (assuming you have the classes “price” and “quantity” on your inputs). I’m using jQuery below:




$('.price, .quantity').change(function() {

  $('.value').val($('.price').val() * $('.quantity').val());

});



This code is not tested, but should get you started.

I Have Tested and it works but total appear NaN not value from price * quantity

What Should I do ??

Either one is NaN. Add a check with isNaN before you try to do the math.

its Ok now, Thanks very much for you help bro

Happy to help!