Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8074817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:46:49+00:00 2026-06-05T14:46:49+00:00

Hello at the moment i’m trying to use jQuery in order to get ids

  • 0

Hello at the moment i’m trying to use jQuery in order to get ids of multiple fields with ajax and send the data to remove it via php.
So far i was able to delete the item but i can’t remove other ids so for and example:

i have a for loop what will get the information off the database as:

 for($i=0; $i < $data; $i++) {
    echo "
    <div class='list-item' data-action='delete' id='".$Data[$i]['ID']."'>
    <a class='title link' href='".$Data[$i]['URL']."' target='_blank'>".$Data[$i]['name']."</a>
    <span class='checkbox' id='".$Data[$i]['ID']."' value='".$Data[$i]['ID']."'></span>
    <div class='thumb'>                             
    <img src='".$Data[$i]['thumb']."' alt='' width='110' height='99'>                               
    <span class='attr'>".$Data[$i]['width'].'x'.$Data[$i]['height']."</span>                                
    <span class='size'>".$Data[$i]['size']."</span>                         
    </div>                          
    <div class='date'>".$Data[$i]['Date']."</div>                     
    </div>
    ";
  }

notice how you see the $Data[$i][‘ID’] with that it’ll print out :

<div class="list-item" data-action="delete" id="89">
<a class="title link" href="http://URL" target="_blank">NAME</a>
<span class="checkbox" id="89" value="89"></span>
<div class="thumb">
<img src="thumb.png" alt="" width="110" height="99">
<span class="attr">100x100</span>
<span class="size">85.2 KB</span></div>
<div class="date">2012-06-11 01:25:20</div>
</div>

<div class="list-item" data-action="delete" id="90">
<a class="title link" href="http://URL" target="_blank">NAME</a>
<span class="checkbox" id="90" value="90"></span>
<div class="thumb">
<img src="thumb.png" alt="" width="110" height="99">
<span class="attr">100x100</span>
<span class="size">85.2 KB</span></div>
<div class="date">2012-06-11 01:25:20</div>
</div>

so with that i’m using jQuery to add a class to both class=”checkbox” and class=”list-item” with selected so that when the event of click or .on(‘click’ function, it will do a confirm window saying “Are you sure you want to remove?” if ok then grab the id of the elements for each and post the data with ajax to have the item removed instantly!
The thing is i need it to work upon multiple ids and have it not add the class of selected to all of class=”checkbox” and class=”list-item” need it to be specific as in, i choose the items of the ids with 84,94,99,& 100 if i do that everything that is selected should have that class of selected not every id

here is my attempt trying to get this to work

<script>
$(function (){
$('.list-item').on('click', function(e) {
$(this).addClass("selected");
if(window.confirm('Are you sure you want to remove?')) {
id = $(this).attr("id");
        //alert(id);
        $.ajax({
            type: 'post',
            url: 'something.php?action=delete&id='+id,
            dataType: 'json',
            data: {

            }, success: function(data) {
                if(data.error === true)
                    {
                        $.errRorBar({ bdS: "error", html: data.message , delay: 5000 });
                    }
                    else
                    { 
                    $.errRorBar({ bdS: "success", html: data.message , delay: 5000});
                    }
            }, error: function(XMLHttpRequest, textStatus, errorThrown) {
                $.errRorBar({ bdS: "error", html: "Opps! Something went wrong!" , delay: 5000 });

                console.log(XMLHttpRequest);
                console.log(textStatus);
                console.log(errorThrown);

                // console.log(XMLHttpRequest.responseText);
            }

        });
        return false;
  }
});
});
</script> 

So how can i do this and how can i make the refresh to update the list making it hide or remove it or something?
At the moment, it will remove the item from the database but only one time for the one item i selected even if i have multiple items chosen,i’ll get a return of “fail to remove”

Anyone here can help me out?
i think i’m missing something but hopefully this was a good explanation of my situation
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:46:51+00:00Added an answer on June 5, 2026 at 2:46 pm

    After looking into your code i have found few glitches:

    1. Element div of class list-items and span of class checkbox having same ids which is against the dom specification. (use prefix before ids like div-89, span-89 etc.).
    2. You are using the request type post but posting the data in url which is get method.
    3. You are sending request on click event of checkbox so it fires everytime when you select it so you cannot delete multiple items using this approach.

    Solution:
    create a seperate button of delete and send request on click of that button.

    Your code would be:

    $('.list-item').click(function() {
        $(this).addClass('selected');
    });
    
    $(.delete).click(function() {
        var delIds = new Array();
        $('.selected').each(function() {
            delIds.push($(this).attr('id'));
        });
    
        $.ajax({
            url: 'something.php?action=delete&id='+delIds.join(),
            dataType: 'json',
            success: function(data) {
                        if(data.error === true)
                            {
                                $.errRorBar({ bdS: "error", html: data.message , delay: 5000 });
                            }
                            else
                            { 
                                $.errRorBar({ bdS: "success", html: data.message , delay: 5000});
                            }
                    }, 
            error: function(XMLHttpRequest, textStatus, errorThrown)        {
                        $.errRorBar({ bdS: "error", html: "Opps! Something went wrong!" , delay: 5000 });
    
                        console.log(XMLHttpRequest);
                        console.log(textStatus);
                        console.log(errorThrown);
    
                        // console.log(XMLHttpRequest.responseText);
                }
        });
    });
    

    Hope this helps you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Story so far.... Hello Stackoverflowers, me again! Right, im learning JQuery at the moment
Hello people :) I'm trying to use strpos() to find whole words in a
Hello I have been using LibTomCrypt to use SHA1 encryption ( for data integrity
I'm trying to get a string displayed in my UITextView the moment the app
I am trying to remove quotes from a string. Example: hello, how 'are you
Hello all I am working on javascript jquery and svg.I want to ask a
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
ok so i have have this {status:0,id:7aceb216d02ecdca7ceffadcadea8950-1,hypotheses:[{utterance:hello how are you,confidence:0.96311796}]} and at the moment
I am trying to use AVR Studio 5 to program an Atxmega64a1 with basic
Hello all i have a wheel picker working but at the moment it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.