We help IT Professionals succeed at work.

javascript array not accepting text from php line

440 Views
Last Modified: 2013-11-26
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
Comment
Watch Question

Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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

Author

Commented:
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; }
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014

Commented:
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.

Author

Commented:
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
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Thanks for the points and thanks for using EE, ~Ray
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
@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!!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.