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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:51:36+00:00 2026-06-13T10:51:36+00:00

My php script puts an image with a hidden checkbox for that image. When

  • 0

My php script puts an image with a hidden checkbox for that image. When the image is clicked, its checkbox is set to checked. I want then to place a outline around the image to show the image is selected without the need for showing ugly checkboxs. To do this i have created a php var called $i that increments for each outputted image to act as the images id, the id is then passed into a Javascript function and called as a jquery selector.

All this works fine, but when the toggleClass event is called it act’s in a way i have never experienced before. It doesn’t fire on the first click, but the second resulting in the highlighting of the image to be done out of sync with the checking of the checkbox i.e.

image > click = no highlight || checkbox checked.

image > second click = image highlighted || checkbox un-checked.

if the addClass event is called this then works, highlighting on the first click. But when rewritten to remove the highlighting on the second click the original problem is back. (i did this using an if else statement with .hasClass(), if had the class ‘highlight’ remove it, else addclass highlight…)

It doesn’t seem to be a problem with the variables, as replacing these with just the number 1 in the HTML & JS the problem still exists.

Right on with the code i am using:

(for the example lets say the php var $i is 1 as it seems a little pointless to write out for loops ect when this part is working fine [also the href=”” of the anchor will be prevented from being followed when a button is clicked, thus making the highlighting possible, this code isn’t written yet so it isn’t causing issues, i just removed href=” for testing])

HTML / PHP

// for this exmaple $i = 1;
// $id is the images unique id, the one used in the server for the image path


<a class='selectbox' id='hil' style='position:relative;' href='show-image.php?id=$id'>
    <div style='display:inline-block; padding:15px;' id=\"$i\" onclick=\"highlight('" . $i . "')\"  class='lifted drop-shadow-sq' >
        <label for=\"$id\">
            <img class='reflect reflect-br' width='150px;' height='150px' src=\"thumb.php?id=$id\">
        </label>
            <input id=\"$id\" style='display:non;' type='checkbox' class=\"show-man\" name='images[]' value='$id'>
    </div>
</a>

Jquery

function highlight(x) { 
id = x;
    $('#' + id).click(function() {
        $(this).toggleClass('highlight');
    });
}

CSS

.highlight img {
box-shadow:0 0 10px #5bb1ce;
}

Thanks for any replies in advance.

  • 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-13T10:51:37+00:00Added an answer on June 13, 2026 at 10:51 am

    Right, after a few hours of head scratching and hair pulling i have come to a solution. It seems the i was using to check and un-check the checkbox was causing the issue. Not to sure why though?

    So i removed this and created a simple Jquery function for the highlighting. (To credit Zefiryn this is a slight modification of his reply.)

    $(document).ready(function(){
        $(".lifted").live('click', function() {
            $(this).toggleClass("highlight");
        });
    });
    

    I then removed the tags from the html and replaced them with a JavaScript function using the images unique id in the id of the checkbox to check/un-check the checkbox.

    <div style='display:inline-block; padding:15px;' id=\"$i\" onclick=\"if (event.target.tagName != 'INPUT') document.getElementById('$id').checked = !document.getElementById('$id').checked\"  class='lifted drop-shadow-sq' >
        <img class='reflect reflect-br' width='150px;' height='150px' src=\"thumb.php?id=$id\">
            <input id=\"$id\" style='display:none;' type='checkbox' class=\"show-man\" name='images[]' value='$id'>
    </div>
    

    The css stayed the same.

    All now seems sorted and is working fine, lastly i must thank Zefiryn for the help above.

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

Sidebar

Related Questions

I have nginx receiving POST requests and a tiny PHP script that puts request
A php script is building the following (very complicated script that is too long
I made a little PHP script that checks if an email is valid. The
I wrote a PHP script that retrieves values from a MySQL Query. I used
I have a PHP script running on my LAMP server that requires certain files
I'm writing a simple php/mysql script that gets all ads I have in my
I want to redirect all to one script e.g. index.php?url=inputurl With if/else I want
I have a PHP script that runs once a day, and it takes a
I have a php script that gets user input (some text and a link),
I have a php script creating a calendar event for each 'event' that 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.