Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-08-2009, 10:48 PM   PM User | #1
xion.truth
New to the CF scene

 
Join Date: Dec 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
xion.truth is an unknown quantity at this point
Javascript delete record from database

This is driving me nuts. I have a html list that is populated from php. When i click one of these items and then click the submit button i want the javascript to take `tranID` and delete that record from the database. my code is below

javascript
Code:
<script language="JavaScript"><!--<br />
function attach_file(frm) {
   if (confirm("Are you sure you want to delete '" + frm.tithlist.value + "'"))
   {
      window.location.href = 'updatTith.php?tranID=' + frm.tithlist.value;
   }
}

</script>
php
PHP Code:
<?php

if(isset($_GET['tranID']))
{

    include 
'../dbcon/config.php';
    include 
'../dbcon/opendb.php';

//get values if input fields
$tranID $_POST['tranID']; //Name

 
$query mysql_query("delete from records where tranID = '$tranID'") or die(mysql_error());
   
header('Location: ' $_SERVER['HTTP_REFERER']);
   exit;

}

?>

html

Code:
<form id="form2" name="form2" method="post" onSubmit="attach_file(form2);">
 <?php
			
			echo "<select tabindex='4' name='tithlist' id='tithlist' size='20'>";
			$res=mysql_query("select date,tranID,name,tith from records where tith <> '0' order by date asc");
			if(mysql_num_rows($res)==0) echo "there is no data in table..";
			else
			for($i=0;$i<mysql_num_rows($res);$i++) {
			$row=mysql_fetch_assoc($res);
			echo"<option ID='tith' value='$row[tranID]'>$row[date]_____$row[tranID]_____$row[tith]_____$row[name]</option>";
		
			}
			echo'</select>';
			
			?>
<input type="submit" name="Submit2" value="Submit" />
<\form>

Last edited by xion.truth; 03-08-2009 at 11:42 PM..
xion.truth is offline   Reply With Quote
Old 03-09-2009, 02:46 AM   PM User | #2
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
You never said what your problem is.

My guess is:
Code:
onSubmit="attach_file(form2);return false">
Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 03-09-2009, 03:16 AM   PM User | #3
xion.truth
New to the CF scene

 
Join Date: Dec 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
xion.truth is an unknown quantity at this point
it never actually updates the database.

should i add return false to the end of the onsubmit?
xion.truth is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:06 AM.


Advertisement
Log in to turn off these ads.