Variable from jQuery to URL

Asked

Viewed 114 times

3

The thing is, I have the following code:

$('body').on("click", ".delete", function() {
   $('#1').val($(this).parents('tr').find('td').eq(0).text());
});

That goes to get the id of a row of a corresponding table clicked row and I wanted to take that value and put it in the URL like this:

window.location('iframes/clientes_apagar.php?cliente_id="Aqui"')
  • Possible duplicate of Concatenate number sum to a string

  • Turns out it didn’t work out at least the way I tried

  • Alter window.location('iframes/clientes_apagar.php?cliente_id="Aqui"') for window.location.href = 'iframes/clientes_apagar.php?cliente_id="Aqui"';

1 answer

1


You can do it this way:

var id_ = $(this).closest('tr').find('td').first().text().trim();

Then concatenate this value in the window.location:

window.location('iframes/clientes_apagar.php?cliente_id="'+id_+'"');

Example:

$('body').on("click", ".delete", function() {
   var id_ = $(this).closest('tr').find('td').first().text().trim();
    $('#1').val(id_);
    // window.location('iframes/clientes_apagar.php?cliente_id="'+id_+'"');
    alert(id_); // apenas para visualização
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
   <tr>
      <td>
         id 1
      </td>
      <td>
         <a class="delete" href="#">Exibir id da linha</a>
      </td>
   </tr>
   <tr>
      <td>
         id 2
      </td>
      <td>
         <a class="delete" href="#">Exibir id da linha</a>
      </td>
   </tr>
</table>

  • Didn’t answer but helped Thank you!!

  • @Shider glad I helped. Thank you!

  • Thank you and sorry for the time you lost!!

  • @Shider Good morning friend! What would be the correct answer for me to adjust?

  • I’ve got it all figured out Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.