Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

241
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda