php - Adding function in a javascript button -


this question has answer here:

i want btn-post-announcement have function when click post button data's in table inserted in database.

<div id='donor_table'>      <div style='height: 600px; width: 100%; overflow: scroll'>          <table id='donor_tbl' border='5' cellpadding='10'>             <thead>             <th>#</th>             <th>announcements</th>             <th>date</th>             <th>time</th>             <th>post</th>             </thead>             <tbody>              <?php             include "connection.php";             error_reporting(0);             $searchannouncement = $_post['searchannouncement'];             $displayann = " select annid,announcement,dateee,timeee announcements_tbl annid '%" . $searchdonor . "%' or announcement '%" . $searchdonor . "%' or dateee '%" . $searchdonor . "%' or timeee '%" . $searchdonor . "%' order annid desc";              $anndata = mysql_query($displayann);             while ($drecords = mysql_fetch_assoc($anndata)) {                 echo "<tr><td>" . $drecords['annid'] . "</td>";                 echo "<td>" . $drecords['announcement'] . "</td>";                 echo "<td>" . $drecords['dateee'] . "</td>";                 echo "<td>" . $drecords['timeee'] . "</td>";                 echo "<td align='center'><input type='button' class='btn-post-announcement button' id=" . $drecords['annid'] . " value='post'></td>";             };             ?>             </tbody>         </table>     </div> </div> </body> </html> <div id="dlg">     <div>         <script type="text/javascript">             $(function () {                 $("#dlg").dialog({                     autoopen: false,                     height: 600,                     width: 780,                     modal: true                 });                 $(".btn-post-announcement").button();                 $(".btn-post-announcement").click(function () {                 })                 $("#donor_tbl").datatable();             });         </script> 

you need ajax achieve this. use jquery so:

js

$(function(){   $('.btn-post-announcement').click(function(){ // on button pressed     var data = {};     var count = 0;    $('td').each(function(){        // each td       data[count++] = $(this).text(); // collect text inside    })     $.post("url.php", data, function(resp){ // send collected data php         console.log(response)     })   }) }) 

url.php

<?php  var_dump($_post); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -