Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
Can anyone help me with this template that is getting the weird value in my textbox

I have the following codes. Im using Django and using raw SQL statement to send data to my template for this part.

views.py (SQL statement part)

cursor = connection.cursor()
tablename= "dev_interface_" + str(device.id)
cursor.execute(f"SELECT interface FROM {tablename} WHERE id >=2")
righttable = cursor.fetchall()

template (Where i loop the SQL)

<table class="table tablesorter">
 <thead>
  <tr>
   <th>Interface registered</th>
   <th>Check to delete</th>
  </tr>
 </thead>
 <tbody>
  {% for item in righttable %}
  <tr>                                            
   <td>{{ item.0 }}</td>
    <td>
     <div class="form-check">
      <input type="checkbox" value="{{item.0}}" class="chkcvalues">
     </div>
    </td>
  </tr>
  {% endfor %}
 </tbody>
</table>
<input type ="text" name="deleteint" id="txtvalues" >

This is how the page look like when i run it: Looping of data in SQL

Script (Coded this to add all the item that is selected for the checkbox in my deleteint)

$(document).ready(function()
    {
        $('.chkcvalues').click(function()
        {
            var txt =""
            $('.chkcvalues:checked').each(function(){
                txt+=$(this).val(txt) + ","
            })
            txt=txt.substring(0,txt.length-1)
            $('#txtvalues').val(txt);
        });
    });

It looks visually fine as the data displayed are correct. But as i tick the checkbox. Within the textbox (deleteint) I declared at the end of my table, it register the value of [object Object] Instead of what i intend it to be. Example if i tick the checkbox of TenGigabitEthernet1/0/5. That should appear in my textbox. And as shown in my code, the checkbox are assign with value="{{item.0}}". Can anyone explain this part to me as I do not get it how {{item.0}} works for the first column but doesnt work in the checkbox.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I try to rebuild your code. Now it works.

$(document).ready(function() {
  $('.chkcvalues').click(function() {
    var txt = ""
    $('.chkcvalues:checked').each(function(i, v) {
      txt += v.value + ","
    })
    txt = txt.substring(0, txt.length - 1)
    $('#txtvalues').val(txt);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table">
  <thead>
    <tr>
      <th>Interface registered</th>
      <th>Check to delete</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>TenGigabitEthernet1/0/5</td>
      <td>
        <div class="form-check">
          <input type="checkbox" value="{{item.0}}" class="chkcvalues">
        </div>
      </td>
    </tr>
    <tr>
      <td>TenGigabitEthernet1/0/6</td>
      <td>
        <div class="form-check">
          <input type="checkbox" value="{{item.1}}" class="chkcvalues">
        </div>
      </td>
    </tr>
    <tr>
      <td>TenGigabitEthernet1/0/7</td>
      <td>
        <div class="form-check">
          <input type="checkbox" value="{{item.2}}" class="chkcvalues">
        </div>
      </td>
    </tr>
  </tbody>
</table>
Checkbox-Value: <input type ="text" name="deleteint" id="txtvalues" >

about 4 years ago · Juan Pablo Isaza Report

0

I had to correct txt+=$(this).val(txt) + "," to txt+=$(this).val() + "," and it worked perfectly

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!