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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:11:57+00:00 2026-05-27T05:11:57+00:00

<div id=image_div> <input type=checkbox /> <img src=1.jpg /> <input type=checkbox /> <img src=2.jpg />

  • 0
<div id="image_div">
<input type="checkbox" />
<img src="1.jpg" />
<input type="checkbox" />
<img src="2.jpg" />
<input type="checkbox" />
<img src="3.jpg" />
<input type="checkbox" />
</div>

On page load, I return a JSON array:

{
    "src":["lml7x8nJzI.jpg","TaR7dALIPJ.jpg","TDE2pWgIfa.jpg","tUtuDx1BEf.jpg"],
    "checked":["lml7x8nJzI.jpg","TaR7dALIPJ.jpg","tUtuDx1BEf.jpg"]
}
  • The src contains all the source names of image and checked is the checked type of check boxes.
  • The checked defines which image is checked (every image has a check box).

I need the final HTML like this:

<div id="image_div">
<input type="checkbox" />
<img src="lml7x8nJzI.jpg" />   
<input type="checkbox" checked />              //this is a checked one
<img src="TaR7dALIPJ.jpg" />    
<input type="checkbox" checked/>                 //this is a checked one
<img src="TDE2pWgIfa.jpg" />
<input type="checkbox" />                    //this is not
<img src="tUtuDx1BEf.jpg" />     
<input type="checkbox" checked />  //this is a checked one
</div>

I can use array contains in JavaScript, or is there a better way?

My attempt:

var initial = "<ul class='gallary'>";
var middle = "";
var end = "</ul>";
var i;

for (i = 0; i < data.src.length; i++)
{
    if (data.checked.contains(data.src[i]))   // How can I do this?
    {
        middle = middle +
            "<li><img src=" +
            "http://localhost/project/user/" +
            "<?php echo $this->session->userdata('username');?>" +
            "/pages/" +
            "<?php echo $this->uri->segment(3);?>" +
            "/images/gallery/" +
            data.src[i] +
            " />" +
            "<br /><input type='checkbox' value=" +
            data.src[i] +
            " checked/></li>";
    }
    else
    {
        middle = middle +
            "<li><img src=" +
            "http://localhost/project/user/" +
            "<?php echo $this->session->userdata('username');?>" +
            "/pages/" +
            "<?php echo $this->uri->segment(3);?>" +
            "/images/gallery/" +
            data.src[i] +
            " />" +
            "<br /><input type='checkbox' value=" +
            data.src[i] +
            " /></li>";
    }
}

var complete = initial + middle + end;
$("#project_gallary_layout").html(complete);
  • 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-27T05:11:58+00:00Added an answer on May 27, 2026 at 5:11 am

    Here’s my complete solution using indexOf

    $(function(){
      var url = 'http://localhost/project/user/<?php echo $this->session->userdata('username'); ?>/pages/<?php echo $this->uri->segment(3); ?>/images/gallery/'
        , complete = '<ul class="gallery">'
    
      data.src.forEach(function(src){
        complete += '<li><img src="' + url + src + '"><input type="checkbox" value="' + src + '"'
        if(data.checked.indexOf(src) > -1){
          complete += ' checked'
        }
        complete += '></li>'
      })
    
      $("#project_gallary_layout").html(complete);
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this html: <div class=nation> <a href=library.php?type=nation&amp;id=America> <div class=nation-image> <img src=nations/America.png alt=snip /> </div>
at the moment i have this <div id=beau> <div> <input type=text id=lun name=lun size=24
Got these two image buttons: <input type=image src=images/Update.png name=btnSubmit value=Update/> <input type=image src=images/Cancel.png value=Cancel
I have simplified my page and here what I have: <html> <head> <meta http-equiv=content-type
<script type=text/javascript> $(document).ready(function($){ $.supersized({ //Background image slides : [ { image : 'images/pendulumWeb.jpg' }
hey, well I have this form <form method=POST action=''> <input type=hidden name=op value=download1> <input
my captcha field <p style=height:30px;><img id=captcha src=includes/secureimage/securimage_show.php?sid=<?php echo md5(time()); ?> alt=CAPTCHA Image /> <a
Possible Duplicate: add an image to a html type input check box or radio
I have checkboxes on a page, when you click a span for each checkbox,
I have this div: <div class=inauguration-image> I do not want this text to display,

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.