Question: I have a table where you can see a full list of entities per type and which son is father of who

PEOPLE

```
ID  | Deleted  |  Type      | Father_id
1   |     0    |   Father   |  null
2   |     0    |   Son      |    1
3   |     1    |   Daughter |    1 
4   |     1    |   Son      |    5
5   |     0    |   Father   |  null
6   |     0    |   Father   |  null
7   |     1    |   Son      |    5
8   |     0    |   Daughter |    5
9   |     0    |   Father   |  null
10  |     1    |   Son      |    6
11  |     0    |   Father   |  null

```

I want to pull the **NumberofDeletedChildren** and **in case father doesn't have sons I have to show it as well**.

```
Father_id   | NumberOfDeletedSons
Father1     |         1
Father5     |         2
Father6     |         1
Father9     |        No Sons
Father11    |        No Sons

```

I made a query to check the total number of children, but I have no idea how to pull the number of child records deleted.

```
SELECT father, COUNT(*) AS numSons FROM PEOPLE where type in ('Daughter','Son') and deleted=0 GROUP BY father

```

Thank you in advance.

Answer: 
Add your script tag below the form, you can use `this` to pass the form to your call back. Use `querySelector` for `:checked` to search inside the form for a checked input.

```
<script type="text/javascript">
function confirmSubmit(form){
    if(form.querySelector(":checked")) {
        window.alert("Thank you");
        return true;
    } else {
        window.alert("Select at least one preference");
        return false;
    }
}

</script>

```

You can pass the form to your call back by updating your `onclick` listener;

```
<form action="FormProcessor.html" method="get"
enctype="application/x-www-form-urlencoded" 
onsubmit="return confirmSubmit(this)">

```

Here is the [fiddle.](http://jsfiddle.net/67xz8vna/)
With jQuery you can do this:

```
function confirmSubmit(){
$('input').each(function(index, item) {
   if(item.checked){
     return true;
   }
});
}

```