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 4564266
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:28:35+00:00 2026-05-21T18:28:35+00:00

I’m working on a CMS at the moment and have been looking for a

  • 0

I’m working on a CMS at the moment and have been looking for a suitable Jquery/Php image manager but can’t find anything that really suits my needs. So I’ve decided to have a go at building the image manager myself. The bad news is I’m not particularly up to speed with my Jquery…actually I know very little. But I’m working my way through it.

The end result will display an unordered list of images.

<ul>
<li><a href="#" id="imgid"><img src="imgsrc" /></a></li>
<ul>

When the user clicks on an image the ID of that image is sent to a Jquery function and stored in an array. The image is highlighted with a border added by addclass(). If the user clicks on a subsequent image that image ID is also sent to the Jquery array and the second image is also highlighted.

This continues until the user doesnt click on any further images. Naturally if the user clicks on an image that is already contained in the Jquery array then it is removed and the highlighted effect is also removed.

Following this the user will select a catalogue item from a select menu that sits below the image list. The ID of that item is also passed to Jquery.

When the user clicks submit the Jquery array and select ID are sent to a PHP script that updates a MySQL table, linking the image ID to the catalogue item ID.

Where I’m up to currently is…I have a lovely unordered list of images.

My questions are

  1. How do I send the image id to the jquery array, and subsequently remove that id if the same image is clicked again
  2. How do I send the Jquery array to the PHP script to be executed

I have got some of this working in code snippets at the moment, but as Jquery is far from my forte Im just rinsing and repeating until I get the code right. Any help would be great.

Mark

So Ive been trying this code snippet, but I think i could be written better.

$(document).ready(function() {
    $("img").click(function(event) {
        var test = (event.target.id);
        if($('img[id=' + test + ']').is('.error'))
            $('img[id=' + test + ']').removeClass("error");
        else
            $('img[id=' + test + ']').addClass("error");
    });
});
</script>

Surely there’s another way to target the img id without having to use ‘img[id=’ + test + ‘]’

Mark

Edited again

$(document).ready(function() {
    $("img").click(function(event) {
        var img_id = (event.target.id);
        var imgArray = new Array();
        if($('img[id=' + img_id + ']').is('.selected')) {
            $('img[id=' + img_id + ']').removeClass("selected");
            $('span[id=check_' + img_id + ']').removeClass("check-ok");
            removeArray();
            }
        else {
            $('img[id=' + img_id + ']').addClass("selected");
            $('span[id=check_' + img_id + ']').addClass("check-ok");
            addArray();
            }
        function removeArray() { 
            alert('Removing from the array');
            }
        function addArray() {
            alert('Adding into the array');
            }
        });
    });

Trying to figure out how to insert the images into the array, and then remove them from the array.

  • 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-21T18:28:36+00:00Added an answer on May 21, 2026 at 6:28 pm

    I’m not really sure what all the bits of your code are doing, but something like this should at least make it a bit more DRY:

    function showMessage(selected) {
        if( true === selected )
          {
          alert('Removing from the array');
          }
        else
          {
          alert('Adding to the array');
          }
    }
    
    $(document).ready(function() {
        $('img').click(function(event, ui)
          {
          $(this).toggleClass('selected');
          var id = $(this).attr('id');
          $('#check_' + id).toggleClass('check-ok');
          showMessage( $(this).hasClass('selected') );
          });
    });
    

    And in jsfiddle (although I replaced img with div for speed).

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I am reading a book about Javascript and jQuery and using one of the

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.