Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

237
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda