Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get all td value of same row by jquery

                {% set i = 0 %}
                {% if user_papers|length > 0 %}
                    {% for user_paper in user_papers %}
                        {% set u_user = user_paper.user %}
                        {% set i = i+1 %}
                        {% set img = u_user.getUserImg() %}

                        {% set relationship = user.getRelationshipWithTarget(u_user.id) %}
                        {% set userAnswer = user_paper.getCompleteAnswer() %}
                        {% set userAnswerCount = userAnswer|length %}

                        <tr>
                            <td>{{ i }}</td>
                            <td>
                                <a href="{{ img }}" data-lightbox="roadtrip"><img src="{{ img }}" alt="User-Image" style="border-radius: 50%;height: 50px;width: 50px"></a><br>
                                {{ u_user.name }}
                                {% if relationship != false %}
                                    <br><span id="" class="badge badge-success" style="font-size: 12px;color: white">{{ t(relationship)}}</span>
                                {% endif %}
                            </td>
                            <td>{{ userAnswerCount }}</td>
                            <td>
                                <select id="" class="current_rating" data-rating="{{ user_paper.teacher_rating }}">
                                    <option value="0"></option>
                                    <option value="1"></option>
                                    <option value="2"></option>
                                    <option value="3"></option>
                                    <option value="4"></option>
                                    <option value="5"></option>
                                </select>
                                <span class="title current-rating">{{ t('rating') }}: {{ user_paper.teacher_rating }}</span>
                            </td>
                            <td>
                                <p>
                                    <textarea id="w3review" name="w3review" rows="4" cols="50">
                                        {{ user_paper.teacher_feedback }}
                                    </textarea>
                                </p>
                            </td>
                            <td>
                                <a class="btn btn-sm btn-primary" href="/{{ module_name }}/{{ controller_name }}/result/{{ user_paper.ref_id }}" target="_blank">{{ t('result')}}</a>
                                <div class="submit_paper btn btn-primary pull-right">{{ t('save') }}</div>

                            </td>
                        </tr>
                    {% endfor %}
                {% endif %}

Okay above is the code , so it will generate multiple row (depending on the database). What i wanted to do is when user click on submit_paper button , able to retrieve {{ user_paper.ref_id }} , {{ user_paper.teacher_feedback }}

            $(document).on('click', '.submit_paper', function () {
            var paper_ref = $(this).closest('td');
                            console.log(paper_ref);

i tried with this code , it always show ‘undefined’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The code you provided should not give you undefined, it should give you a table cell element. I’m not sure why that would happen but the cod ebelow should give you the data you require.

$(document).on('click', '.submit_paper', function () {
    // The anchor just before has the ref_id in the url
    var ref_url = this.previousElementSibling.href;        
    var ref_id = ref_url.split('/').pop();
    console.log(ref_id);
    // The teacher feedback is in the only textarea in the row(which id should be unique btw)
    var teacher_feedback = $(this).closest('tr').find('textarea').val();
    console.log(teacher_feedback);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading