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

  • SEARCH
  • Home
  • 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 601051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:40:22+00:00 2026-05-13T16:40:22+00:00

I’m trying to implement a starring system akin gmail, being able to mark an

  • 0

I’m trying to implement a starring system akin gmail, being able to mark an item important by clicking on a graphic.

if($starred == 1){
        $starred = '<img class="starred" id="row_'.$trouble_ticket_id.'" src="images/icons/silk/award_star_gold_3.png" alt="Star">';
    }
    else{
        $starred = '<img class="unstarred" id="row_'.$trouble_ticket_id.'" src="images/no_star.png" alt="No Star">';
    }

$content.= '<td><a href="ticketEdit.php?id='.$trouble_ticket_id.'"><img src="images/icon_edit.png" alt="Edit" /></a></td><td><a href="adminTicketDetail.php?id='.$trouble_ticket_id.'">'.$ticket_code.'</a></td><td>'.$requested_by.'</td><td>'.$department.'</td><td>'.$telephone.'</td><td>'.$room_number.'</td><td>'.$subject.'</td><td>'.$original_date_request.'</td><td style="text-align: center;">'.$starred.'</td>';


<script type="text/javascript">
    $(document).ready(function() {
        $("img.unstarred").click(function(){
            $(this).attr("src", "images/icons/silk/award_star_gold_3.png");
            $(this).attr("alt", "Starred");
            $(this).removeClass('unstarred').addClass('starred');
            $.get("star_it.php", { id: $(this).attr("id") } );
        });
        $("img.starred").click(function(){
            $(this).attr("src", "images/no_star.png");
            $(this).attr("alt", "Unstarred");
            $(this).removeClass('starred').addClass('unstarred');
            $.get("star_it.php", { id: $(this).attr("id") } );
        });
                 }); 
    }); 
</script>';

As you can see upon the click of the image it send an ajax request to star_it.php with the URL variable attached to it corresponding to the ID of the element clicked.

This works fine on the first click, it changes the image, the ALT text and the class using jQuery. However, upon successive clicks, it seems that the original path is still taken.

So if the image is starred after the first click, jQuery will continue to star the item (at least on the webpage). I have used Firebug to determine that this is in fact happening. On first run it will change a non-starred image to starred and make the change in the database. On second click and further clicks, it still goes through the $(“img.unstarred”).click(function()) when it should be going through the img.starred function and marking the image unstarred.

I do all this by removing and adding css classes. When a starred img is clicked i remove the starred css class and add the unstarred css class. However, this does not seem to be working. I really can’t use the ID of the img for onclick because it is dynamically generated.

Any ideas?

  • 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-05-13T16:40:22+00:00Added an answer on May 13, 2026 at 4:40 pm

    Consolidate it down in to one function and use css to give a div’s the correct background image rather than assigning an image different sources. Use the power that css gives you.

    <style>
    .unstarred{
        background: url(images/no_star.png);
    }
    .starred{
        background: url(images/icons/silk/award_star_gold_3.png);
    }
    </style>
    
    <div class="star unstarred" />
    

    Your javascript would be simply this then since your star_it.php knows own to toggle based on the id sent to it.

    $(document).ready(function() {
        $("div.star").click(function(){
            $(this).toggleClass('unstarred').toggleClass('starred');
            $.get("star_it.php", { id: $(this).attr("id") } );
        });
    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.