Search code examples
codeigniterjasny-bootstrap

how can i show this $data value in the form input field?


how to show $data value in form input field?

<head>
    <script>
        $(function () {
            $("#task_id").change(function () {
                var task_id = $(this).val();
                var url = "status/tasks/get_task_info/" + task_id;
                $.ajax({
                    url: url,
                    beforeSend: function () {
                        $(".load-taskinfo").html('<img src="images/ajax/ajax-loader10.gif">');
                    },
                    success: function (response) {
                        $data = JSON.parse(response);
                    }
                });
            });
        });
    </script>
</head>
<body>
<div class="span3">
    <div class="control-group <?php echo (form_error('progress_percent')) ? 'error' : ''; ?>">
        <label class="control-label" for="progress_percent">Progress (In %) :</label>
        <div class="controls">
            <?php echo form_input(array(
                'name' => 'progress_percent',
                'id' => 'progress_percent',
                'maxlength' => 160
            )); ?>
            <?php if (form_error('progress_percent')) : ?>
                <span class="help-inline">
                <?php echo form_error('progress_percent'); ?>
              </span>
            <?php endif; ?>
        </div>
    </div>
</div>
</body>

Solution

  • In your success callback, use jQuery selector to select the input by ID or by name, and fill its value.

    success: function (response) {
        var $data = JSON.parse(response);
        $('#progress_percent').val($data);
    }