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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:55:23+00:00 2026-06-09T16:55:23+00:00

I am having a problem with a block of my code, this section creates

  • 0

I am having a problem with a block of my code, this section creates boxes of chocolates based on what a user chooses in a previous step and what data is pulled from the database in the api script.
the problem is that it doesn’t work without the alert(‘hi’) in it. if i take that out it will just create an empty box without dropping the flavors in it, the flavor the flavors are inserted with the createFlavorArray function.

var product = new Array();
var price = new Array();
var size = new Array();

$(function () {
      $.ajax({
        type: 'POST',
        url: 'phpscripts/api.php',      
        data: "",
        dataType: 'json',    
          success: function(rows)        
        {
        count = 0;
          for (var i in rows)
          {
            var row = rows[i];          
              product[count] = row[0];
              price[count] = row[1];
              size[count] = row[2];
              count++;
          }
        } 
      });
    });

//b = box
//o = option that is inside the box
//nextBoxId is the box id
//nextFlavorId is the option or flavor id

var nextBoxId = 1;
var nextFlavorId = 1;
var orderCap = 0;
var subTotal = 0;
var numOfChocolates = 0;
var numOfBoxes = 0;

$(document).ready(function(){

    while (halfPoundBoxes > 0) {
            $("#boxes").append('<div id="b'+nextBoxId+'"></div>');
            $('#b'+nextBoxId).addClass('div-table-selection');
            $('#b'+nextBoxId).append($('#minusBox').clone().attr('id', "m"+nextBoxId));
            $('#b'+nextBoxId).append('<div style="display:table-row"></div>');

            //call the function to loop through and create the number of flavor options needed
            var x = 0;
            alert('hi');
            while(x < product.length){
                if ('1/2lb Box' == product[x]) {
                    createFlavorArray(size[x], nextBoxId);
                    subTotal += price[x] * 1;
                    $('#b'+nextBoxId).attr('title', product[x]);
                }
                x++;

            }
            //clone the delete box button and make it visible

            $('#m'+nextBoxId).show(500);
            $('#b'+nextBoxId).append("<br />");

            if (orderCap == 0) {
            $('#boxes').append('<div id="msg"><p>If you wish to add another box to your order select the size and click +1 Box.</p></div>');
            }

            $("#m"+nextBoxId).click(function() {
                    $(this).parent().remove();
                orderCap--;
                //if they're ordering zero boxes hide the order button
                //remove total price
                //remove the message
                if (orderCap == 0)
                {
                    document.getElementById('orderBtn').style.display = "none";
                    $("#msg").remove();
                    $("#totalPrice").empty();
                }
                if (orderCap < 10)
                {
                    $("#cap").remove();
                    $("#addBox").show(500);
                }
                var y = 0;
                while (y < product.length) {
                    if ('1/2lb Box' == product[y]) {
                    subTotal -= price[y] * 1;
                    numOfChocolates -= size[y] * 1;
                    }
                    y++;
                }
                $('#totalPrice').html("<p>Sub Total: " + subTotal + "</p>")
                //subtract the new
                $('#finalpaypal').val(subTotal);

            });
            nextBoxId++;
            orderCap++;
            numOfBoxes++;
            $('#totalPrice').html("<p>Sub Total: " + subTotal + "</p>")
            halfPoundBoxes--;   
    }
  • 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-09T16:55:24+00:00Added an answer on June 9, 2026 at 4:55 pm

    You need to put the code in a function and run it after the ajax success is finished

    ...
    $(function () {
      $.ajax({
        type: 'POST',
        url: 'phpscripts/api.php',      
        data: "",
        dataType: 'json',    
          success: function(rows)        
        {
        count = 0;
          for (var i in rows)
          {
            var row = rows[i];          
              product[count] = row[0];
              price[count] = row[1];
              size[count] = row[2];
              count++;
          }
          do_after_ajax();
        } 
      });
    });
    
    function do_after_ajax(){
            while (halfPoundBoxes > 0) {
            $("#boxes").append('<div id="b'+nextBoxId+'"></div>');
            $('#b'+nextBoxId).addClass('div-table-selection');
            ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with this very simple block of code. please give me
I'm having difficultly figuring out how to write this block of code... function myFunction(x,y,z)
I'm having a problem with TRY...CATCH blocks. Can someone explain why the following code
I am having a problem understanding how array.sort{ |x,y| block } works exactly, hence
I'm having a problem with using delegate inside Blocks. With ARC on, this is
Im having problem in my UIscrollView ,this is what I have done: Whenever a
I am having problem to get a numerical value for this expression where I
I'm having problem with datagrid view. I have attached an image with the code
Im having a problem, I have managed to get some code to make a
I'm hoping someone can help me with this annoying little problem I'm having. I'm

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.