How do I make an interaction between two tables (<table>) with AJAX?

Asked

Viewed 81 times

0

I need to make an interaction between two tables in a side tab, where initially an "answer" table is hidden and the "question" table will be available and so on input search above them I type something via AJAX will automatically appear in the table "question", until then resolved

How to hide the second table which is the one I want to appear only after I click on an item? That is, the question of the first table and the first table is now.

  • If the question is ONLY of "disappear" and "appear", you can use $('#tabela_para_sumir').css('display', 'none'); and $('#tabela_para_aparecer').css('display', 'block');, addition in the element of id="tabela_para_aparecer" the parameter style="display:none;". If you are not using Jquery, use similar functions for the purpose of changing the display CSS. You can also get by using $(...).hide() and $(...).show(), for the respective functions, if you use Jquery.

  • You only need to use ajax if you are going to make a request in the bank. In the question you do not mention it. If you are not making any request you can try what the friend above suggested.

  • So Inkeliz and Joao Paulo, thank you for the explanations, helped me clear my mind, well I used in Document.ready the $("#teste_faq_reply"). Hide(); and then when accessing the page this hidden beauty but ai in the table where I can capture the BD data I need that are the table questions in mysql called "confidential name"_Faq when clicking on a line where this the question I need to appear the answer to later I cannot make appear to another table or pebble which type and tag I have already tried to use "p" to appear the answer and hide the question.

  • Thanks for the tips I managed to make disappear and appear another table with the answers now my next step is to make appear exactly the answer of the question I selected, anyone have any tips? heartfelt thanks!

1 answer

1

To know which line you have chosen you can do the following, in html:

    <table id="table">
 <tr id="1">
  <td>A</td>      
  <td>B</td>      
 </tr>
 <tr id="2">
  <td>C</td>      
  <td>D</td>      
  </tr>    
</table>

and in jquery to get that same line you can do the following

$('tr[id=' + id + ']').remove(); 
// id será o valor que queres passar no caso é 2 , neste caso vai apagar a linha

example in a function:

function qualLinha(){
$('#table tr').click(function (event) {
      alert($(this).attr('id')); //alerta qual foi o id da linha que selecionaste
 });
}

Browser other questions tagged

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