dimanche 24 septembre 2017

Checkbox insertion from a database to another jsp javascript

I am displaying data from a database and I have a checkbox for each displayed data the user has the option to check those check boxes and insert them into another database when they click add. My code:

<script>
function toggle(source) {
var checkboxes = document.querySelectorAll('input[type="checkbox"]');
for (var i = 0; i < checkboxes.length; i++) {
    if (checkboxes[i] !== source)
    checkboxes[i].checked = source.checked;

  }
}       

</script>

<table id="example" class="table">
<thead>
    <tr>
                <th><input name="select_all" type="checkbox" value="1" onclick="toggle(this);"> Select All </input></th>
                <th>ID Number</th>
                <th>Family Name</th>
                <th>First Name</th>
                <th>Middle Name</th>
                <th>Email</th>  
                <th>Contact Number</th>
        </tr>
    </thead>
<%
while (rs.next()) { 
%>
    <tbody>
    <tr class="success">
                <td><input id="box" type="checkbox" name="attend"></input></td>
                <td><%=rs.getString(5)%></td>
                <td><%=rs.getString(2)%></td>
                <td><%=rs.getString(4)%></td>
                <td><%=rs.getString(3)%></td>
                <td><%=rs.getString(6)%></td>
                <td><%=rs.getString(7)%></td>
            </tr>
        </tbody>
<% } %>
<script>
function insert(e){
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "7597",
database: "database"
});
forEach (box e in example.Rows)
 {

     CheckBox chk = (CheckBox)r.FindControl("checkRow");

     if (chk!==null && chk.Checked)
     {
        con.connect(function(err) {
        if (err) throw err;
        console.log("Connected!");
var sql = "INSERT INTO twintowerbombing SELECT * FROM "=+e;
        con.query(sql, function (err, result) {
        if (err) throw err;
        console.log("record inserted");
   });
}); 
     }
  }
}
</script>




Aucun commentaire:

Enregistrer un commentaire