Avatar of sydneyguy
sydneyguyFlag for Australia asked on

javascript array not accepting text from php line

have some javascript that is working fine until i add one line
it builds five arrays that hold data from out of a table and just grabs the field and pops it in that array,

if i change the $item->tissue (this is text) to $item->userid (its a number ) it will collect the information
tissue is available to be grabbed, but for some reason it does not like using text in this position cannot see why it will not work

***** the below line does not work
echo ("      price_list4[".$curcatnum."][".$itemnum."] = ".$item->tissue."; ");
***** the below line does work
echo ("      price_list4[".$curcatnum."][".$itemnum."] = ".$item->userid."; ");

see the image for the display of whats in the .$item

var price_list=new Array();
var price_list1=new Array();
var price_list2=new Array();
var price_list3=new Array();
var price_list4=new Array();



// IT ALREADY HAS THE DATA BY THIS POINT
// LOOK AT ITEM  
function initprice(){
<?php
 
      $curcatnum = -1;
      $itemnum = -1;
      $curcat = '';
      // THIS IS THE READ POINT
      foreach ($this->items as $item) {
            $itemnum++;            
      
          // IF CURENT CATEGORY DOESNOT= CATEGORY
            
            if ($curcat != $item->category) {
                  $curcatnum++;
                  $itemnum = 0;
                     $curcat = $item->category;
                echo ('price_list['.$curcatnum.'] = new Array();'."\n");
                echo ('price_list1['.$curcatnum.'] = new Array();'."\n");
                echo ('price_list2['.$curcatnum.'] = new Array();'."\n");
                echo ('price_list3['.$curcatnum.'] = new Array();'."\n");
                echo ('price_list4['.$curcatnum.'] = new Array();'."\n");
               
            //    price_list4[0] = price_list1[$curcatnum];
            };
            echo ("      price_list[".$curcatnum."][".$itemnum."] = ".$item->cost."; ");
            echo ("      price_list1[".$curcatnum."][".$itemnum."] = ".$item->cost1."; ");
            echo ("      price_list2[".$curcatnum."][".$itemnum."] = ".$item->cost2."; ");
            echo ("      price_list3[".$curcatnum."][".$itemnum."] = ".$item->cost3."; ");

***** the below line does not work            
            echo ("      price_list4[".$curcatnum."][".$itemnum."] = ".$item->tissue."; ");
            
      //alert(".$item->userid.");

            $userval = $item->tissue;
      }
?>
}


javascriptarray
JavaScriptPHPScripting Languages

Avatar of undefined
Last Comment
Chris Stanyon

8/22/2022 - Mon
SOLUTION
Dave Baldwin

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
sydneyguy

no error message, the code runs up till i put that line in, at this time you select a + button and it increments a number and then add the increment to the total, with the line out the number increments and the total is added to.
put the line in and the number increments and but no total is acted upon.
i also cannot see what is wrong, when i run the de bugger over it in php i can see the values and there there , change it to a number from the items, and it works change it back to text value and it stops. no errors are displayed
looking at the page it looks ok, great idea a must say. good thinking

below is a drop out around the array

function show_desc(iid) {
	if (iid.style.display == '') iid.style.display='none'; else iid.style.display='';
};

var price_list=new Array();
var price_list1=new Array();
var price_list2=new Array();
var price_list3=new Array();
var price_list4=new Array();



// IT ALREADY HAS THE DATA BY THIS POINT
// LOOK AT ITEM  
function initprice(){
price_list[0] = new Array();
price_list1[0] = new Array();
price_list2[0] = new Array();
price_list3[0] = new Array();
price_list4[0] = new Array();
	price_list[0][0] = 300.00; 	price_list1[0][0] = 25.00; 	price_list2[0][0] = 135.00; 	price_list3[0][0] = 30.00; 	price_list4[0][0] = skin; 	price_list[0][1] = 145.00; 	price_list1[0][1] = 30.00; 	price_list2[0][1] = 135.00; 	price_list3[0][1] = 30.00; 	price_list4[0][1] = skin; 	price_list[0][2] = 125.00; 	price_list1[0][2] = 25.00; 	price_list2[0][2] = 155.00; 	price_list3[0][2] = 35.00; 	price_list4[0][2] = skin; 	price_list[0][3] = 145.00; 	price_list1[0][3] = 30.00; 	price_list2[0][3] = 155.00; 	price_list3[0][3] = 35.00; 	price_list4[0][3] = skin; price_list[1] = new Array();
price_list1[1] = new Array();
price_list2[1] = new Array();
price_list3[1] = new Array();
price_list4[1] = new Array();
	price_list[1][0] = 125.00; 	price_list1[1][0] = 25.00; 	price_list2[1][0] = 135.00; 	price_list3[1][0] = 30.00; 	price_list4[1][0] = skin; 	price_list[1][1] = 145.00; 	price_list1[1][1] = 30.00; 	price_list2[1][1] = 135.00; 	price_list3[1][1] = 30.00; 	price_list4[1][1] = skin; 	price_list[1][2] = 125.00; 	price_list1[1][2] = 25.00; 	price_list2[1][2] = 155.00; 	price_list3[1][2] = 35.00; 	price_list4[1][2] = skin; 	price_list[1][3] = 145.00; 	price_list1[1][3] = 30.00; 	price_list2[1][3] = 155.00; 	price_list3[1][3] = 35.00; 	price_list4[1][3] = skin; price_list[2] = new Array();
price_list1[2] = new Array();
price_list2[2] = new Array();
price_list3[2] = new Array();
price_list4[2] = new Array();
	price_list[2][0] = 125.00; 	price_list1[2][0] = 25.00; 	price_list2[2][0] = 0.00; 	price_list3[2][0] = 0.00; 	price_list4[2][0] = skin; 	price_list[2][1] = 145.00; 	price_list1[2][1] = 30.00; 	price_list2[2][1] = 0.00; 	price_list3[2][1] = 0.00; 	price_list4[2][1] = skin; 	price_list[2][2] = 125.00; 	price_list1[2][2] = 25.00; 	price_list2[2][2] = 0.00; 	price_list3[2][2] = 0.00; 	price_list4[2][2] = skin; 	price_list[2][3] = 145.00; 	price_list1[2][3] = 30.00; 	price_list2[2][3] = 0.00; 	price_list3[2][3] = 0.00; 	price_list4[2][3] = skin; 	price_list[2][4] = 138.00; 	price_list1[2][4] = 28.00; 	price_list2[2][4] = 0.00; 	price_list3[2][4] = 0.00; 	price_list4[2][4] = skin; 	price_list[2][5] = 160.00; 	price_list1[2][5] = 33.00; 	price_list2[2][5] = 0.00; 	price_list3[2][5] = 0.00; 	price_list4[2][5] = skin; 	price_list[2][6] = 138.00; 	price_list1[2][6] = 28.00; 	price_list2[2][6] = 0.00; 	price_list3[2][6] = 0.00; 	price_list4[2][6] = skin; 	price_list[2][7] = 160.00; 	price_list1[2][7] = 33.00; 	price_list2[2][7] = 0.00; 	price_list3[2][7] = 0.00; 	price_list4[2][7] = skin; price_list[3] = new Array();
price_list1[3] = new Array();
price_list2[3] = new Array();
price_list3[3] = new Array();
price_list4[3] = new Array();
	price_list[3][0] = 835.00; 	price_list1[3][0] = 710.00; 	price_list2[3][0] = 626.00; 	price_list3[3][0] = 0.00; 	price_list4[3][0] =  Primary Cells; 	price_list[3][1] = 990.00; 	price_list1[3][1] = 842.00; 	price_list2[3][1] = 742.00; 	price_list3[3][1] = 0.00; 	price_list4[3][1] =  Primary Cells; 	price_list[3][2] = 1070.00; 	price_list1[3][2] = 910.00; 	price_list2[3][2] = 802.00; 	price_list3[3][2] = 0.00; 	price_list4[3][2] =  Primary Cells; 	price_list[3][3] = 1030.00; 	price_list1[3][3] = 876.00; 	price_list2[3][3] = 772.00; 	price_list3[3][3] = 0.00; 	price_list4[3][3] = Primary Cells; }

function check_event(checknum,plusmin){
	var sum_ = new Array();
	var price_treshold = 25;
	var amtx;
	var amtlft;
	var amtbought;
	var amtstore;
	var elamt;
	var j;
		var jj = 0;

Open in new window

ASKER
sydneyguy

this here does not seem right especially the end
price_list4[3][3] = 466; } where is the rest

      price_list[3][0] = 835.00;       price_list1[3][0] = 710.00;       price_list2[3][0] = 626.00;       price_list3[3][0] = 0.00;       price_list4[3][0] = 466;       price_list[3][1] = 990.00;       price_list1[3][1] = 842.00;       price_list2[3][1] = 742.00;       price_list3[3][1] = 0.00;       price_list4[3][1] = 466;       price_list[3][2] = 1070.00;       price_list1[3][2] = 910.00;       price_list2[3][2] = 802.00;       price_list3[3][2] = 0.00;       price_list4[3][2] = 466;       price_list[3][3] = 1030.00;       price_list1[3][3] = 876.00;       price_list2[3][3] = 772.00;       price_list3[3][3] = 0.00;       price_list4[3][3] = 466; }
SOLUTION
Chris Stanyon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Dave Baldwin

I think Chris is right.  In...

price_list4[0][0] = skin;

'skin' will be considered the name of a variable, not a 'value' because it is not quoted.  And of course, there is no such variable.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
sydneyguy

it is javascript with php wrapped around it

thanks for the input went through the code and came up with the line below that works fine

echo (" price_list4[".$curcatnum."][".$itemnum."] = '".$item->tissue."'; ");

thanks for all the help its now up and running thanks every one
Ray Paseur

Thanks for the points and thanks for using EE, ~Ray
Chris Stanyon

@sydneyguy

When you say you 'went through the code and came up with the following' - I think what you you actually meant to say was 'I copied Chris's code exactly and it worked!!'.

Just for future reference, here on EE, it's considered good practice to accept the answer that actually answers your question...call me old fashioned but I'm funny like that!!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.