OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

AJAX/JQUERY show and hide button

  • Thread starter Thread starter mengmeng
  • Start date Start date
M

mengmeng

Guest
Here is my previous post and thank you to sir @Satpal that I finally got the button working. But now I have another bug.

This is what my goal that will happen to my site: every I click a certain row (".emp_delete") the .deleteBtn shows up and hides when clicked on another row.

The button doesn't show up after searching. Can someone help me?

Code:
$(document).ready(function(){

        $('#employee_list').delegate( ".emp_delete", 'click', function() {
              var ID=$(this).attr('id'); 
              $("#delete_"+ID).show();
        });

        $('#employee_list').delegate(".deleteBtn", 'click', function(){

            var ID=$(".emp_delete").attr('id');

            if (confirm("Are you sure you want to delete?")) {
            var dataString = 'emp_id='+ID;

            $.ajax({
                type: "POST",
                url: "<?php echo site_url('c_employee/delete_employee'); ?>",
                data: dataString,
                cache: false,
                success: function(html){
                    location.reload();
                }
            });
        }
        else
            return false;

        });

        $("#searchText").keypress(function(){   //change to keypress
            var search = $("#searchText").val();
            var dataString = 'search='+search;


            $.ajax({
                url: "<?php echo site_url('c_employee/get_search'); ?>",
                type: 'POST',
                dataType: 'json', 
                data: dataString,
                cache: false,
                success: function(data){
                        console.log(data);
                        $("#employee_list").empty();

                        $.each(data, function(index, val) {

                            $("#employee_list").append('<tr class="emp_delete" id="'+val.emp_id+'"><td>'+val.emp_id+'</td><td>'+val.last_name+'</td><td>'+val.first_name+
                                '</td><td>'+val.middle_in+'</td>'+
                                '<td><input type="button" value="Resigned Employee" class="deleteBtn" id="delete_"'+val.emp_id+'"></td></tr>');
                        });

                    }
                 });

             });

    });

    $(document).mouseup(function(){
        $(".deleteBtn").hide();

    });

<p>Here is my previous post and thank you to sir @Satpal that I finally got the button working. But now I have another bug.</p>

<p>This is what my goal that will happen to my site:
every I click a certain row (".emp_delete") the .deleteBtn shows up and hides when clicked on another row.</p>

<p>The button doesn't show up after searching. Can someone help me?</p>

<pre><code>$(document).ready(function(){

$('#employee_list').delegate( ".emp_delete", 'click', function() {
var ID=$(this).attr('id');
$("#delete_"+ID).show();
});

$('#employee_list').delegate(".deleteBtn", 'click', function(){

var ID=$(".emp_delete").attr('id');

if (confirm("Are you sure you want to delete?")) {
var dataString = 'emp_id='+ID;

$.ajax({
type: "POST",
url: "<?php echo site_url('c_employee/delete_employee'); ?>",
data: dataString,
cache: false,
success: function(html){
location.reload();
}
});
}
else
return false;

});

$("#searchText").keypress(function(){ //change to keypress
var search = $("#searchText").val();
var dataString = 'search='+search;


$.ajax({
url: "<?php echo site_url('c_employee/get_search'); ?>",
type: 'POST',
dataType: 'json',
data: dataString,
cache: false,
success: function(data){
console.log(data);
$("#employee_list").empty();

$.each(data, function(index, val) {

$("#employee_list").append('<tr class="emp_delete" id="'+val.emp_id+'"><td>'+val.emp_id+'</td><td>'+val.last_name+'</td><td>'+val.first_name+
'</td><td>'+val.middle_in+'</td>'+
'<td><input type="button" value="Resigned Employee" class="deleteBtn" id="delete_"'+val.emp_id+'"></td></tr>');
});

}
});

});

});

$(document).mouseup(function(){
$(".deleteBtn").hide();

});
</code></pre>
 

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top