0

<script>
function removeAllRowsContainingCheckedCheckbox() {
  alert("hello");
    for (var rowi= table.rows.length; rowi-->0;) {
        var row= table.rows[rowi];
        var inputs= row.getElementsByTagName('input');
        for (var inputi= inputs.length; inputi-->0;) {
   //alert("inside for");
            var input= inputs[inputi];

            if (input.type==='checkbox' && input.checked) {
   //alert("indide if ")
                row.parentNode.removeChild(row);
                break;
            }
        }
    }
}


</script>
<html>  
<head>

</head>
<body>  
   <form action="" method="post" enctype="multipart/form-data">  
  
<table border="1" id="table">  
   <tr>  
      <td colspan="2">Select Technolgy:</td>  
   </tr>  
   <tr>  
      <td>c</td>  
      <td><input type="checkbox" name="techno[]" ></td>  
   </tr>  
   <tr>  
      <td>hadoop</td>  
      <td><input type="checkbox" name="techno[]" ></td>  
   </tr>  
   <tr>  
      <td>core java</td>  
      <td><input type="checkbox" name="techno[]" ></td>  
   </tr>  
   <tr>  
      <td>Javascript</td>  
      <td><input type="checkbox" name="techno[]" ></td>  
   </tr>  
   <tr>  
      <td>springs</td>  
      <td><input type="checkbox" name="techno[]" ></td>  
   </tr>
   <tr>  
      <td colspan="2" align="center"><input type="submit" value="submit" name="sub"></td>  
   </tr>
      
      <input type='button' value='del' onclick='removeAllRowsContainingCheckedCheckbox();'>Click me to delete
</table>  
 
</form>  
<?php  
if(isset($_POST['sub']))  
{  
 $db = pg_connect("host=localhost port=5432 dbname=postgres user=postgres password=ndem$123");
 if(!$db){
      echo "Error : Unable to open database\n";
   } else {
      echo "Opened database successfully\n";
   }

 
$checkbox1=$_POST['techno'];  
$chk="";  
foreach($checkbox1 as $chk1)  
   {  
      $chk .= $chk1."";  
    echo '<script>alert("Inserted Successfully")</script>';
   }  
$in_ch=pg_query("insert into news_table(technology) values ('$chk')");  
echo "the check box value is " . $in_ch;
if($in_ch==1)  
   {
  echo '<script>alert("Inserted Successfully")</script>';
  echo "Records created successfully\n";
   }  
else  
   {  
     echo pg_last_error($db);
   }  
   pg_close($db);
}  
?>  
</body>  
</html>  
For the submit can i able to write javascript function with out using
$checkbox1=$_POST['techno'];  
    $chk="";  
    foreach($checkbox1 as $chk1)  
       {  
          $chk .= $chk1."";  
           echo '<script>alert("Inserted Successfully")</script>';
       }

above code because if(isset($_POST['sub'])) is reloading the already submitted checkboxs in the table so user may confuse after delete the page will again show all the check box those who are submitted also .. Please suggest alternatives for this any ways i want to insert the checked checkboxes into database but my thought is to delete the checked submitted also in the table.

zakhefron
  • 1,403
  • 1
  • 9
  • 13
user28536
  • 123
  • 2
  • 9
  • generic idea described in another answer http://stackoverflow.com/a/5004276/1826279 – Mike S Jun 26 '16 at 09:12
  • here i want only javascript sir can see suggest any. Specifically how the above foreach is useful and what does it means can you explain – user28536 Jun 26 '16 at 09:21
  • I would not be better than documentation for `foreach` http://php.net/manual/en/control-structures.foreach.php . You cannot edit database without server side processing, server side language is php, so you can not edit database with client side javascript only. – Mike S Jun 26 '16 at 09:28
  • sir here i can able that rows insert into database after insertion of that on page again those checkboxs remain in the table without checked. Is there any way to remove those checked and inserted rows to delete on the user interface table – user28536 Jun 26 '16 at 09:33

0 Answers0