Jump to content

[SOLVED] using jquery to delete from database


exhaler

Recommended Posts

hi,

i'm trying to use jquery to delete some data from the database.

first the user is presented with a combobox (select box) to choose an option

<select id="client_id" name="client_id">
<option value="">Select Client</option>
<option value="70">test</option>
<option value="69">test2</option>
</select>

 

on selection i retrieve the data without refreshing using qjuery ajax functions

<script type="text/javascript">
$(document).ready(function() {
	var checking_html = '<img src="../images/loading.gif" alt="" />Loading...';

	$("#client_id").change(function() {
		$("#modules").html(checking_html);
		get_modules();
	});

	$("a.delete_module").live("click", function(event) {
		$("#message").html('Deleting...');
		delete_module();
	});
});

// Delete selected module
function delete_module(){
        // Get the Clien id
	var module_id = $('#delete_id').val();

	//use ajax to run the check
	$("#message").html(module_id);           
    }

// Fetch modules for selected client
function get_modules(){
        // Get the Client id
	var client_id = $('#client_id').val();

	//use ajax to run the check
	$.post("get_modules.php", { client_id: client_id, style: 'table' },
		function(data){
			$("#modules").html(data);
	});           
    }
</script>

 

what comes up is a table with the results and two links edit and delete

capturexw.th.png

 

delete link:

<a href=\"#\" class=\"delete_module\" >Delete/a>
<input type=\"hidden\" value=\"$id\" id=\"delete_id\"/>

 

i use the input field to get the id of the module, here is my problem when i click on delete link on any one of them i get the value of the first row

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.