When clicking on a name, appear in another div

Asked

Viewed 592 times

1

I have a project developed in Bootstrap, which when clicking on link Products, will open a Modal ( from Bootstrap ) with the listed products. However, I would like that when clicking on one of the products the modal closed and the product clicked appeared in a <div> under the link clicked. Even the modal and the list of products I managed to do, but the name of the product appears below the link clicked I couldn’t. Someone could help me?

<script type="text/javascript">
    function Aparecer(produto){
      var nome;
      document.getElementById("Produtos").innerHTML = produto;
    }
  </script>
<a href="#" onclick="javascript:Aparecer(<?php echo $produto; ?>)">Selecionar</a>
<div id="Produtos"></div>
  • 2

    Could show what you’ve tried?

  • 1

    Hello fakarella. I edited and put the code.

  • So, if I understood correctly, when the user choose a product in modal, is for the name appear below the link Products and close the modal?

  • That... even the modal managed to arrive....

  • I made a change to the code. I managed to make it appear on the same page, but how I would make the modal to close and the selected product appear below the link I reported earlier on the other page?

2 answers

1


Put an id on div below the Products link (say: id="produtoSelecionado").

Now just use it in Javascript, along with the modal closure (I assume the use of jQuery):

function Aparecer(produto){
  document.getElementById("produtoSelecionado").innerHTML = produto;
  $('#myModal').modal('hide');
}
  • 1

    Hello fakarella. I will make a test here... qq thing I return. Thanks!

0

Hello, I think this missing the quotation marks in <?php echo $product; ?>.

try like this: '<?php echo $product; ?>'

  • Hi Filipe. I can actually take the product information and put it inside the div 'Products', but this only works if you have it on the same page. The problem is that the products open in the Bootstrap modal and I would like to click on the desired product, the modal to close and the product name to appear on another page.

Browser other questions tagged

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