Click here to Skip to main content
15,883,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to update and delete the data from table using bootstrap modal window . i have passed id for that particuar data to be updated or delete. but iam not able to access that id into modal window. as well as while update modal call it only show one record on that modal
thanks in advance

What I have tried:

HTML
<div class="action-buttons bigger-125" align="center">
																			<a href="#edit-event-modal">
																				
																			</a>

																			<a href="#del-event-modal">
																			^__i class="fa fa-times">
																			</a>
																			<!--<a href="#myModal" class="btn">Delete Project</a>-->
																</div>

modal.php
PHP
<!-- Delete Project Modal -->
    <div id="del-event-modal" class="modal fade">

        <div class="modal-dialog">

            <div class="modal-content">

                <div class="modal-header">

                    

                    <h4 class="modal-title">Confirmation</h4>

                </div><!--//modal-header-->

                <div class="modal-body">

                    <p class="text-warning">Do you want to Delete this project?</p>
					
			
                </div> <!--//modal-body-->

                <div class="modal-footer">

                 <!--   -->
				     

				    


                </div> <!--//Modal-footer -->

            </div><!--//modal-content-->

        </div><!--//modal-dialog-->

    </div><!--//modal-->
<!--// Delete Project Modal -->

<!-- edit project modal -->
  <div id="edit-event-modal" class="modal fade">

        <div class="modal-dialog">

            <div class="modal-content">

                <div class="modal-header">

                    

                    <h4 class="modal-title">Edit Project</h4>

                </div><!--//modal-header-->

                <div class="modal-body">

               <div>
				 
				</div>
                </div> <!--//modal-body-->

                <div class="modal-footer">

                   <!-- 
				    
-->

                </div> <!--//Modal-footer -->

            </div><!--//modal-content-->

        </div><!--//modal-dialog-->

    </div><!--//modal-->
<!--//edit project modal-->


JavaScript
	$('#del-event-modal').on('show.bs.modal', function (event) {
			
			  var button = $(event.relatedTarget); // Button that triggered the modal
			  var recipient = button.data('id'); // Extract info from data-* attributes
			  // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
			  // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
			  var modal = $(this);
			 
			  modal.find('.modal-body #id').val(recipient);
			  
				$('#del').on('click', function (event) {
					var x = document.getElementById("id").value; 
					 $.ajax({
						url: 'delproject.php',
						type: 'POST',												
						data :{value:x} ,
						success: function(data){
						var data = JSON.stringify(data)
						alert("id sent is "+data);	
						//window.location.href="projects.php";													   
						}
					});
					
				 });
			});

$('#edit-event-modal').on('show.bs.modal', function (e) {
			
			 	 //get data-id attribute of the clicked element
				var bookId = $(e.relatedTarget).data('id');
		
				//populate the textbox
				$(e.currentTarget).find('input[name="proid"]').val(bookId);
				//var x = document.getElementById("proid").value; alert("pid"+x);

			
				/*$('#edit').on('click', function () {
				
					var x = document.getElementById("proid").value;  alert("pid"+x);
					var pnm = document.getElementById("pnm").value;  alert("pnm"+pnm);
					var pcity = document.getElementById("pcity").value;  alert("pcity"+pcity);
					var feature = document.getElementById("p_feature").value;  alert("feature"+feature);
					var spec = document.getElementById("p_spec").value;  alert("spec"+spec);


					 $.ajax({
						url: 'editproject.php',
						type: 'POST',												
						cache: 'false',
						data :{value:x,pnm:pnm,pcity:pcity,feature:feature,spec:pspec} ,
						success: function(data){
							var data = JSON.stringify(data)
							//alert("id sent is "+data);	
							window.location.href="projects.php";													   
						}
					});
					
				 });*/
			});
Posted
Updated 3-Oct-16 4:13am
v2

1 solution

I might be missing something but the reason you don't have an ID in javascript code is because you don't have any data attributes defined on your button.

So say you are using your edit button (I added Edit as your link should even appear as its an empty anchor tag):

HTML
<a href="#edit-event-modal">Edit</a>


In your javascript you access the calling button and Id as such

JavaScript
var button = $(event.relatedTarget);
var recipient = button.data('id');


This is not how i do this functionality so I'm not sure if relatedTarget works. However, your recipient should always be null because there is no data-id attribute on your edit button link. You need to do the following to get some value in your recipient

HTML
<a href="#edit-event-modal">Edit</a>
<!-- Assuming your are looping over this html or populating it via some model, data-id="2" should be something like data-id=""...not sure if you need echo $myId, my PHP is rusty -->
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900