![]() |
Ajax Help Please, trying to call a php script via an onclick event?
is it possible to use an onclick event command on a text link to call a php script which deletes a specific row from a mysql db table?
here is what i have so far. my text link code Code:
<a class="deleteRow" onclick="PHP Code:
unfortunately when i press on the text link nothing happens, or so it appears! if i open firebug and then click on the console tab it gives the following error Code:
SyntaxError: syntax errorcan anyone help me with this please? many thanks Luke |
well , since something else on the page is affecting this code, you ned to show more.
also what syntax is this : data: {joodb field|id} ? I dont see where your getting the id of the item to delete and assigning it to the ajax call. also why add a script block to every delete button you generate? you could jsut use soemthing like Code:
$('.deleterow').click(function (e) { |
hi, thanks for your quick reply,
the site is a joomla website and i'm using a plugin to access the db and its the plugin which creates the syntax {joodb field|id} - that code is telling the script to get the id value from the database, thats how im getting the correct id values the full form code is Code:
<h2 class="filter">Waiting List</h2>thanks Luke |
maybe it should be data: {'id':joodb field|id} ?
perhaps you are just supplying the ID and not a key to pair the ID value with? |
i think you are correct as alot of example i've seen state a key to the data, but unfortunately the script still doesnt work :(
|
can you see anything wrong with this code
Code:
<a class="deleteRow" onclick="EDIT ==== Ok noticed that one of the brackets were incorrect ) instead of } :( now its throwing up another syntax error TypeError: $(...) is null??? any ideas? thanks |
[QUOTE=LJackson;1306735]can you see anything wrong with this code
Code:
<a class="deleteRow" onclick="give me a few Ill show you maybe an easier way to do this. |
here's a different way.
add this to the head section in a script block, or even at the bottom of the body element in a script block. OK so I am using .on, this will bind the function to any new elements in the dom. If you are using an older version of jquery you may need to use .live instead of .on. Ok so what I am doing is assigning this function to any element with a class of deleterow. Code:
$(function(){Code:
<a class="deleteRow" rel="joodb field|id" href="#">Delete</a>ok, so hopefully this works. I am assuming youd like to do some simple error handling? Also did you want anything on the currrent page to change, as you will still be viewing a now deleted record? |
ok thanks mate appreciate it,
i've been going round in circles with this :( because im using joomla im not sure how to add the script to the head section of the page, i'll have a look around and get back to you :) |
ok found out where to put it, i had to chance the script slightly as there was a missing bracket, and changed .deleterow to .deleteRow so its now
Code:
<script type="text/javascript">my php code is PHP Code:
many thanks Luke |
i've just been told on the joomla forum that joomla code doesnt work outside of joomla? so i'm guessing thats why nothing seems to be working :(
is it possible to delete db records using just javascript or jquery? thanks |
| All times are GMT +1. The time now is 05:26 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.