Okay so my problem is that I have a table that contains 5 elements. One of the elements is a checkbox and another is an anchor. When I click the anchor it suppresses the default action and adds a class to the anchor. I have the attribute "data-name" equal to the name of the checkbox. I need to accomplish the following.
When I click on the anchor with the data attribute, I need the checkbox with the same name to be checked.
My code is below.
<script>
$(document).ready(function(){
var clicks= 0;
var DELAY=700;
$("a").on("click", function(e){
e.preventDefault();
if($(e.target).hasClass("selected")){
$(e.target).removeClass("selected");
} else {
$(e.target).addClass("selected");
}
clicks++; //count clicks
if($(e.target).hasClass("selected")){
var data_name = $(e.target).data('name');
if($("input[name="+data_name+']').attr('name') === data_name)
$('input[name='+data_name+']').find('input[name='+data_name+']').prop('checked', true);
}
if(clicks === 1) {
timer = setTimeout(function() {
clicks = 0; //after action performed, reset counter
}, DELAY);
} else {
clearTimeout(timer); //prevent single-click action
window.location = $(event.target).attr("href");
clicks = 0; //after action performed, reset counter
}
});
$("a").on("dblclick", function(e){
e.preventDefault(); //cancel system double-click event
});
});
</script>
The table looks like the attached picture (it looks nicer than the code that is available).

the example table row is the following
<?php
// $files is the number of files in each directory.
for($i=0; $i<$files;$i++){
?>
<tr>
<td>
<input type="checkbox" name="todelete<?= $i?>" value="404.shtml">
</td>
<td>
<i class="fa fa-file-text-o center"></i>
</td>
<td>
<a href="http://kregelbagel.com/404.shtml" value="" data-name="todelete">404.shtml</a>
</td>
<td>437</td>
<td> bytes</td>
</tr>
<?php
}
?>