1

<!DOCTYPE html>
<html>
<body>

<p>Check form to approve and delete news feeds</p>

<form action="form_action.asp">


<table id="dataTable" width="350px" border="1" style="width:100%">
  <tr>
<TD><INPUT type="checkbox" name="chk[]" onchange/>Times of india</TD>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
<TD><INPUT type="checkbox" name="chk"/>Hindu</TD>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
<TD><INPUT type="checkbox" name="chk"/>BBC</TD>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
  </tr>
</table>

<br>
<input type="button" onclick="myFunction()" value="Approve">
<input type="button" onclick="myFun()" value="delete">
<br><br>
<input type="text" id="order" size="50">
<input type="submit" value="Submit">
<table>
</form>

<script>
function myFunction() {
    var coffee = document.forms[0];
    var txt = "";
    var i;
    for (i = 0; i < coffee.length; i++) {
        if (coffee[i].checked) {
            txt = txt + coffee[i].value + " ";
        }
    }
    document.getElementById("order").value = "You ordered a coffee with: " + txt;
}


function myFun() {
    var coff = document.forms[0];
    var txt1 = "";
    var j;
    for (j= 0; j < coff.length; j++) {
        if (coffee[j].checked) {
            txt1 = txt1 + coffee[j].value + " ";
        }
    }
    document.getElementById("order").value = "You ordered a coff with: " + txt1;
}
</script>
</body>
</html>

Expected form should be like below captured like:

Checked and approved row goes to postgres database using PHP code like below is the code form getting expected.

     <!DOCTYPE html>
     <html>
     <head>
     <script>
      function approve(tableID) {
 <?php
   //connecting to database
  $db = pg_connect("host= port=5432 dbname=NEWS user=postgres password=");
  if(!$db){
   echo "Error : Unable to open database\n";
    } else {
  echo "Opened database successfully\n";
 }
//setting default time zone
date_default_timezone_set('Asia/Kolkata');

  $chkbox = $_POST['chk'];
 foreach($chkbox as $a => $b)
 echo "$chkbox[$a]  <br />";

  var rowCount = table.rows.length;
        var row = table.insertRow(rowCount);

        var colCount = table.rows[0].cells.length;

        for(var i=0; i<colCount; i++) {

       //inserting news into database table
                                    $query = "INSERT INTO   ndem_news_table(news_link,   news_title,   news_date, news_source, news_time) VALUES('".$news_link."','".$news_title."','".$news_date."','".$dk."','".$dt."')";
                $result = pg_query($query);
                if (!$result) {
                    //$errormessage = pg_last_error();
                    echo "Error with query: ";
                    //exit();
                }
                else
                {
                   echo "Row Inserted Successfully <br>";
                }
        }
  //php code to insert into data base
 }


  function delete(tableID)
 {
   echo'i am inside of delete';
       try {
                   var table = document.getElementById(tableID);
                   var rowCount = table.rows.length;

                   for(var i=0; i<rowCount; i++) 
                    {
                            var row = table.rows[i];
                            var chkbox = row.cells[0].childNodes[0];
                            if(null != chkbox && true == chkbox.checked)
                            {
                                 if(rowCount <= 1)
                                {
                                  alert("Cannot delete all the rows.");
                                  break;
                                }
                             table.deleteRow(i);
                             rowCount--;
                             i--;
                         }          
                     }


       }
       catch(e) {
        alert(e);
       }
    }
   </script>
   </head>
    <body>

  < button onclick="approve()">Approve</button>
   <button onclick="delete()">delete</button>
   <table id="dataTable" width="350px" border="1" style="width:100%">
    <tr>
   <TD><INPUT type="checkbox" name="chk[]" onchange/></TD>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
 </tr>
 <tr>
 <TD><INPUT type="checkbox" name="chk"/></TD>
 <td>Eve</td>
<td>Jackson</td>
<td>94</td>
 </tr>
 <tr>
<TD><INPUT type="checkbox" name="chk"/></TD>
<td>John</td>
<td>Doe</td>
<td>80</td>
 </tr>
 </table>

 </body>
 </html>

My table here is hard coded one I want it to be dynamically generated one that table data I am getting from XML feeds of news channels.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user28536
  • 123
  • 2
  • 9
  • Can you please show what you have done so far? We need to see code that maybe doesn't work but at least shows what you are trying to do and that you are making an effort – brianlmerritt Jun 21 '16 at 05:13
  • @brianlmerritt how can i make that table dynamically can u provide any reference links – user28536 Jun 21 '16 at 05:21
  • No, sorry. You need to do the work, and come back with something that you can show your effort. That, or you need to pay someone who can do the work for you – brianlmerritt Jun 21 '16 at 05:23

0 Answers0