S
S
SoGood962019-03-27 13:31:06
JavaScript
SoGood96, 2019-03-27 13:31:06

How to add a dynamic field with a value to a form?

Hello. There is a function:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#add').click(function(){
            var str = '<div>';
            str+= '<input type="text" value=""/> ';
            str+= '<input type="button" value="-" class="remove"/>';
            $('#sites').append(str);
        });
        $('.remove').live('click', function() {
            $(this).parent('div').remove();
        });
    });
</script>

It adds an empty box to the div below:

echo CHtml::openTag('div', ['id' => 'sites']);
echo CHtml::closeTag('div');


How can I change it to add a field of this format:

echo $form->dropDownList($door,'type',$door->typeList(),
    ['name' => DoorSale::class.'[type]['.$door->id.']']);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2019-03-27
@webinar

This is:

echo $form->dropDownList($door,'type',$door->typeList(),
    ['name' => DoorSale::class.'[type]['.$door->id.']']);

php. The widget generates html, so you just need to output this html and copy it, then paste it into js. But the widget also registers js for validation, so I'm not sure that you need what you are asking.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question