JavaScript Get value of <li> element from value attribute value from element jquery,element value from,value element of

I am developing a small website for a school project. On one page I iterate over an array which is populated via SQL query. The data will be displayed like this:

<ul class="list-group">
    <li class="list-group-item" name="id" value="36"><span class="badge">9999</span>Testval</li>
</ul>

The name of that li element is always static but the value is filled in with PHP. The value refers to the ID in the DB. I am trying to write a query for a delete statement which looks like this:

DELETE FROM `Kredit` WHERE ID=id;

The id should be retrieved when the user clicks the delete button on that specific li element. There will be multiple li elements which all have a different id. Is it possible to retrieve the id in the value attribute with PHP?

I searched on Stackoverflow for this question but all the questions were referring to the value between the li tags in my case "testval".

Answer:1

In my opinion you need Javascript to do this, jQuery code for this will loke like below. I dont see the delete button to be more specific, but i will explaine the code and hope to be clear enough for you.

$( "#delete" ).click(function() { // when delete is clicked
var id = $(this).attr("value");   // get id value of clicked li's delete
$.ajax({
        type: 'GET',
        cache: false,
        aysync: true,
        dataType: 'json',
        data: { delete : id},
        url: "ajax.php", // cal ajax.php with ?delete=123, use $_GET['delete']
        success: function(data){
            $(this).closest('li').remove(); // if ajax is done, remove this li
        }
});

This example is for value id, i don't think you would like to search in DB by strings like testval instead of unique id.

Answer:2

I'm building an hybrid app using ionic. Inside this app I decided to have Require.js as a dependency loader (maybe not the best choice but I'm used to work with that and since I have lots of projects ...

I'm building an hybrid app using ionic. Inside this app I decided to have Require.js as a dependency loader (maybe not the best choice but I'm used to work with that and since I have lots of projects ...

  1. warning tried to load angular twice

I have to restrict user to enter only numbers in a field in Angular2->form I have solution but backspace is not working in input field Can anybody have proper solution for that? form.html <...

I have to restrict user to enter only numbers in a field in Angular2->form I have solution but backspace is not working in input field Can anybody have proper solution for that? form.html <...

  1. restrict textbox input to numbers c#
  2. restrict textbox input to numbers
  3. restricting textbox input to numbers only in c#
  4. restricting textbox input to letters only
  5. restricting textbox input to numbers only
  6. restrict input in textbox javascript
  7. restricting input to textbox allowing only numbers
  8. wpf restrict textbox input length
  9. xaml restrict textbox input
  10. wpf restrict textbox input
  11. c# restrict textbox input
  12. restrict user input in textbox javascript
  13. restrict keyboard input to textbox javascript
  14. textbox restrict input

I know JQuery is a code smell in ReactJS because it traverses the entire DOM to do it's work. But, I've found some places where it's hard NOT to use it. This is one instance where I'd like to find a ...

I know JQuery is a code smell in ReactJS because it traverses the entire DOM to do it's work. But, I've found some places where it's hard NOT to use it. This is one instance where I'd like to find a ...

I'm kind of stuck here in this situation, where I need my app to reload when changing from one "project" to another. I've tried many things and I have been searching over and over to find a solution. ...

I'm kind of stuck here in this situation, where I need my app to reload when changing from one "project" to another. I've tried many things and I have been searching over and over to find a solution. ...

  1. angularjs ui-sref-opts