0

So I have code to show the unique title whenever icon clicked and showing on modal.

<a style="background-color:#5a85dd; color:white; padding:10px; border-radius:10px; margin-top:20px; " data-toggle="modal" data-target="#popUp" onClick="showModal(<?php echo $id; ?>)">

and I called the title based on id with <p id="title"></p>

the problem is, I want to store title value to make sql query, but I still cant figure it out how.

here is the javascript showModal().

<script>
function showModal(id)
{
    $("#title").text($("#title"+id).text());
    
}
</script>

1 Answer 1

0

I Hope this helps, If you are missing something.

function showModal(id){
  let title = $("#title"+id).text()
  $("#title").text(title)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
  <body>
    <ul>
        <li><a onClick="showModal(1)" href="javascript:void(0)">Icon 1</a>
        
        <p id="title1">Title 1</p>
        </li>
        <li><a onClick="showModal(2)" href="javascript:void(0)">Icon 2</a>
        <p id="title2">Title 2</p>
        </li>
        <li>        <p id="title3">Title 3</p>
        <a onClick="showModal(3)" href="javascript:void(0)">Icon 3</a></li>
    </ul>
     
     <!-- Title Goes here -->
     <p id="title">Title goes here when clicked on icon</p>
    
  </body>
</html>

Not the answer you're looking for? Browse other questions tagged or ask your own question.