1

i need to get the value of a variable in a javascript function to put it in a textfiled.

Javascripts function:

function obtenerArrendatario(){
    arrendatario_id = $.fn.yiiGridView.getSelection('arrendatario');
    alert(arrendatario_id);
}

The alert give me the id of the selected row but i need to put the id in the textfield to save/create the form

Gridview

<div class="row">
    <?php echo $form->labelEx($model,'zf_arrendatarios_arrendatario_id'); ?>
    <?php 
        $arrendatarios = new ZfArrendatarios;
        $this->widget('bootstrap.widgets.TbGridView',
            array(
            'id'=>'arrendatario',
            'selectableRows'=>1,
            'selectionChanged'=>'obtenerArrendatario',
            'type'=>'striped bordered condensed',
            'dataProvider'=>$arrendatarios->search(),
                'filter' => $arrendatarios,
            'template'=>"{items}\n{pager}",
            'columns'=>array(       
                array('name'=>'arrendatario_id_personal', 'header'=>'DNI',),
                array('name'=>'arrendatario_nombre', 'header'=>'Nombre'),
                array('name'=>'arrendatario_email', 'header'=>'Email'),   
            ),
        ));
        ?>
        <?php
        echo $form->textfield($model,'zf_arrendatarios_arrendatario_id',array('class'=>'input input_r input_pryk', 'value'=>$arrendatario));
    ?> 
    <?php echo $form->error($model,'zf_arrendatarios_arrendatario_id'); ?>
</div>

So i need that id that the function capture to fill my textfield.

I tried

$arrendatario= "<script> document.write(arrrendatario_id) </script>"; 

But it print me the string not the value.

2
  • are you want to store value in textfield with name of zf_arrendatarios_arrendatario_id? Commented Jan 10, 2014 at 15:48
  • Yes, fill the textfiled with the variable Commented Jan 10, 2014 at 16:27

1 Answer 1

2

For your requirement, you can set the textfield value in below js function

function obtenerArrendatario(){
    arrendatario_id = $.fn.yiiGridView.getSelection('arrendatario');
   $(".input_pryk").val(arrendatario_id );// input_pryk should be class for this text field alone.
}

Then you will get in controller while submitting the form.

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.