Delete row from mysql database using javascript and php

I am new to javascript and php and am trying to build a page with a select list and a delete button.
If the user highlights a value in the select list box which they want to delete and then pushes the delete button, I want the record to be deleted and the current page to be refreshed. Can anyone point me in the right direction?
//Category Edit Form
@mysql_select_db($database) or die( "Unable to select database");
IF ( ISSET($_POST['orgcodepass']) ) {
$varorgcode = $_POST['orgcodepass'];
$sqlupdate = "delete from tmp_org_service_cat_codes where org_service_cat_code = $varorgcode";
Print  "<script type='text/javascript'>
function alertSelectedIndex(selId)
$.post(Catedit.php,'orgcodepass':'selId'); }
//$sql =   "delete from tmp_org_service_cat_codes where org_service_cat_code = $orgcode"
Echo "<select name=\"orgmaincatscurrent\" id=\"orgmaincatcodescurrent\" multiple=\"multiple\" size=\"5\">";
$querytemp="select b.service_category, b.service_category_code from tmp_org_service_cat_codes a inner join service_cat_lookup b
on a.service_cat_code = b.service_category_code ORDER BY b.service_category";
While ( $rowtemp = mysql_fetch_array($resulttemp) ) {
    echo "<option value = \" " . $rowtemp['service_category_code'] . " \" >" . $rowtemp['service_category'] . "</option>";
Echo "</select>";
print "<input type=\"button\" value=\"alert\" onclick=\"alertSelectedIndex('orgmaincatcodescurrent');\" />";
echo "</script>";
PRINT "<BR /><BR /><BR />";
$query_avail="Select a.service_category, a.service_category_code from service_cat_lookup a
Where a.SERVICE_CATEGORY_CODE not in (select distinct b.SERVICE_CAT_CODE
from tmp_org_service_cat_codes b)";
Echo "<select name=\"orgmaincatsavail\" id=\"orgmaincatcodesavail\" multiple=\"multiple\" size=\"5\">";
While ( $rowavail = mysql_fetch_array($result_avail) ) {
    echo "<option value = \" " . $rowavail['service_category_code'] . " \" >" . $rowavail['service_category'] . "</option>";
Echo "</select>";
print "<input type=\"button\" value=\"alert\" onclick=\"alertSelectedIndex('orgmaincatcodesavail');\" />";
echo "</script>";

Open in new window

Who is Participating?
OpalelementConnect With a Mentor Commented:
Helpful links: adding/removing items selecting all items(for when you submit the form, you will want to do this onsubmit) how to capture delete key

Code snippet is to find out the keycode you need in the last link.
<script language=javascript>
function f()
window.document.onkeydown= f

Open in new window

szewkamConnect With a Mentor Commented:
well, but if the page has to be refreshed after deleting the row then using JS isn't neccessary ;). You should just use forms with php :)
OpalelementConnect With a Mentor Commented:
Didn't notice that lol

Just let them click one and when they hit delete it submits the form, then in PHP delete it:)
OpalelementConnect With a Mentor Commented:
Thought this was the javascript section, I have been in there all day. Sorry for the JS code:)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.