0

I am using java script function in yii _form view in this function i store value in variable and these variable i want to access in yii textfield

so please tell me how access textfield input from javascript variable in yii Here is my javascript function i try this but its showing me blank result

<script language="javascript">
function get_data(element)
    {
       var te_id = $(element).val();
           document.getElementById('data').value=te_id;
    }
</script>
<?php echo $form->TextField($model,'data',array('value'=>'')); ?>
1
  • 1
    how are you calling this get_data method? Commented Sep 23, 2013 at 7:48

1 Answer 1

2

Your code shows that you want to access the values, after initializing it, so you should add html options :

<?php echo $form->TextField($model,'data',array('onclick'=>'get_data(this)')); ?>

an use your get_data function .

or assign an ID to it

<?php echo $form->TextField($model,'data',array('id'=>'myInput')); ?>

and use a button to do the change:

<script>
$(document).ready(function(){
    $('#someButton').click(function(){ // change the value on some button click
        var inputValue = $('#myInput').val();
        //now assign it to ther place
        $('#otherInput').val(inputValue);
     });
});

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.