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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.