0

I am trying to populate an html field with some text being queried using jQuery Ajax. The data being sent to the function view is received back on page load. The callback data can be seen in the console. However the data value itself is not populated in the input field.

Why my code below is failing:

$('.clsSomeTxt input').val(data.recdValue);

Whereas in the console it shows:

console.log('The value received back is: ' + data.recdValue);

I have tried using form's id also, without success.

Edit

<table id="xHeader">

        {% for fieldX in form.visible_fields %}
            <tr>
            <th>{{ fieldX.label_tag }}</th>
                <td>
                    {{ fieldX.errors }}


                    {% if fieldX.name == "model_id" %}
                        {{ fieldX }}<input type="text" class="clsSomeTxt" id="clsSomeTxt" readonly style="background: lightgrey; width: 320px">
                    {% else %}
                        {{ fieldX }}
                    {% endif %}

                </td>
            </tr>
        {% endfor %}
</table>
2
  • Add your html too, guess your class or your selector is wrong Commented Jan 20, 2020 at 14:05
  • @Pedram added.. Commented Jan 20, 2020 at 14:19

1 Answer 1

1

As I mentioned in comment you are using wrong selector, input already has clsSomeTxt class, your selector is totally wrong; you select an input inside of clsSomeTxt, but this is class of input. So the right selector is:

$('input.clsSomeTxt').val(data.recdValue);

Or just:

$('.clsSomeTxt').val(data.recdValue);
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.