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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:28:54+00:00 2026-06-18T14:28:54+00:00

So this is a problem I have seen all over the internet but I

  • 0

So this is a problem I have seen all over the internet but I cannot for the life of me figure out why it won’t work.

For people who will have an idea of what I’m attempting – I have loaded in the static input stuff using .html(contentVariable) and it works fine but once I put the checkbox creation in a for loop everything goes to pot and only the first check box element seems to be working and have styles applied.

So I’m running a query on the server which is returning a json object in order to populate my checkboxes. In the JS I am using ajax to get this json object and loop through the contents to populate the checkboxes. The ‘result’ variable in the example below is returning 3 results and that side of things is working fine (if people realise that I’m not actually echoing out results from the returned object).

So my guess is I’m not using the .trigger() in the right place or correctly at all. Any help would be appreciated.

Many thanks.

HTML

        <!-- register page -->
    <div data-role="page" id="two">
        <script type="text/javascript" src="js/friendsList.js"></script>
        <div data-role="header">
            <h1>New Project</h1>
            <a href="#two" class="ui-btn-left"  data-rel="back" data-icon="back" data-transition="flip">Back</a>
        </div>
        <div data-role="content">
            <form id='registerUser' action="" method="POST">
                <div data-role="fieldcontain" class="checkWrap">

                </div>
                <button type="button" aria-disabled="false">Submit</button>
            </form>
        </div>
    </div><!-- /page two -->   

JS

$(document).delegate('#two', 'pageshow', function() {

var userId = localStorage.getItem('userId');
var friendsListContent = "";

$.ajax({
    url: 'http://www.mysite.co.uk/app/friends/listFriends.php',
    type: 'post',
    data: {'userId': userId},
    dataType: 'json',
    crossDomain : true,
    timeout: 5000,

    success: function(result){
    friendsListContent = "<fieldset data-role='controlgroup'><legend>Choose as many snacks as you'd like:</legend>";

        for(var i = 0; i < result.length; i++){
            friendsListContent += "<input type='checkbox' name='checkbox-1a' id='checkbox-1a' class='custom' /><label for='checkbox-1a'>Cheetos</label>";           
        }

    friendsListContent += "</fieldset>";

    $('.checkWrap').html(friendsListContent);
    $('.checkWrap').trigger('create');
    $("input[type='checkbox']").checkboxradio("create");
    },

    error: function(){
        alert('There was an error loading the data. Contact the admin.');
    }

});

});
  • 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-18T14:28:56+00:00Added an answer on June 18, 2026 at 2:28 pm

    Okay so the answer is the fact that the numbers in the classes and names weren’t being iterated through with each of the checkbox items.

    In the for loop I changed it to this…

    friendsListContent += "<input type='checkbox' name='checkbox-" + i + "a' id='checkbox-" + i + "a' class='custom' /><label for='checkbox-" + i + "a'>Cheetos</label>";           
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen this question asked all over the net, but haven't seen an answer
I've seen that a few instances of this problem have been raised already. However,
NOTE: I have solved the majority of this problem but have run into a
I've searched google and SO for a solution to this problem but have not
I have looked all over the Internet and all over Stack Overflow and I
I've done some research on this problem and have seen a handful of possible
I have seen this error before but got around it by entering values manually,
I took over another project and have fixed everything else except this one problem.
probably a straightforward to the trained eye but I have agonised over this for
I have a strange problem in PHP, hopefully someone has seen this before. I

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.