1
?php foreach($participants as $participant) {
 echo "<tr>";
 echo "<td>" . $participant['Vorname'] . "</td>";
 echo "<td>" . $participant['Auto'] . "<img id=$participant[name_id] onclick='deleteDriver()' class='delete' src='img/tonne.gif' align='right' data-url='backend/queries.php?decision=deleteDriver&id=".$participant['name_id']."'/></td>";
 echo "</tr>";
 }
 ?>
 function deleteDriver()
 {
 var dataString = "decision=deleteDriver";
 $.ajax({
 type: 'POST',
 url: 'queries.php',
 data: dataString
 }
 })
 }
 </script>

When I push the button the function is not called. Why?

Eric Galluzzo
3,2411 gold badge22 silver badges20 bronze badges
asked Jan 4, 2016 at 12:45
5
  • 1
    ?php is not a valid php opening tag. Where is the start tag for <script> ? Commented Jan 4, 2016 at 12:46
  • And you have HTML content inside <script> tags, some many things are wrong with above code Commented Jan 4, 2016 at 12:47
  • You have add extra } in your js code as well. And missed ; after AJAX function end. Commented Jan 4, 2016 at 12:48
  • Console inside the function Commented Jan 4, 2016 at 13:36
  • tryed all still doesent work Commented Jan 4, 2016 at 14:08

2 Answers 2

1

try with this code.

<?php
 foreach($participants as $participant) {
 echo "<tr>";
 echo "<td>" . $participant['Vorname'] . "</td>";
 echo "<td><a onclick='deleteDriver()'>" . $participant['Auto'] . "<img id=$participant[name_id] class='delete' src='img/tonne.gif' align='right' data-url='backend/queries.php?decision=deleteDriver&id=".$participant['name_id']."'/></a></td>";
 echo "</tr>";
 }
 ?>
 <script>
 function deleteDriver()
 {
 var dataString = "decision=deleteDriver";
 $.ajax({
 type: 'POST',
 url: 'queries.php',
 data: dataString
 })
 }
 </script>
answered Jan 4, 2016 at 12:52
Sign up to request clarification or add additional context in comments.

2 Comments

Why should the OP "try this"? A good answer will always have an explanation of what was done and why it was done that way, not only for the OP but for future visitors to SO.
the link is now on my text but i want it on my img
1

You have missed <script> open tag before function deleteDriver(). Please add and retry. Try as below :

<?php
foreach($participants as $participant) {
 echo "<tr>";
 echo "<td>" . $participant['Vorname'] . "</td>";
 echo "<td>" . $participant['Auto'] . "<img id='".$participant['name_id']."' onclick='deleteDriver()' class='delete' src='img/tonne.gif' align='right' data-url='backend/queries.php?decision=deleteDriver&id=".$participant['name_id']."'/></td>";
 echo "</tr>";
}
?>
<script>
 function deleteDriver()
 {
 var dataString = "decision=deleteDriver";
 $.ajax({
 type: 'POST',
 url: 'queries.php',
 data: dataString
 }
 });
 }
</script>
answered Jan 4, 2016 at 12:47

1 Comment

You forgot about echo and the HTML content inside the <script>, go over the code again.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.