Click here to Skip to main content
13,733,067 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi all I am a newbie in JavaScript, i am stuck with this problem hopefully anyone can help out thank you . I am trying to create an Application where allow the user to input what kind of food , price that the customer have consume in a restaurant. First the User is required to key in the name of the User . Then when he or she click the" input name" button a new user object is created. I have created a constructor call UserCustomer(). when a new object is created , it will create element inside such as the customer name, price, and a remove user button, if the user want to remove the customer from the list. After the User click the input name button.the user will be navigate to the Add food page. The user is required to input the food and price which the customer consume,the user can add as many as he wants, when the user click the add Food Button , the program will push the food and price enter into the new customer object created previously.

When the User Click the "done adding". the program will push all value into the array "newMakanUser".

And then finally the function will print loop through this "newMakanUser" and print out the Value

The Result i get is 0: [object Object] 1: [object Object]

The Result that i want to get is

For Example

John Food :Burger Fries cola Price :2.4,1.5,1.0 Linda Food : salad Fruits juice Price : 3.5, 1.0,1,6

What I have tried:

//This is  a New Array
var newMakanUser = [];
var newButton  = [];
var placeHolder = [];
var TempVar=[];  
var TempUSer= "";
    
function UserCustomer(nameU){
    this.nameUser = nameU;
    this.Food = [];
    this.Price= [];
    var button = document.createElement("button");
    button.innerHTML = "Remove " +nameU +" from list ";

// 2. Append somewhere
    var body = document.getElementsByTagName("body")[0];
    body.appendChild(button);
}

function outArray() {
        newMakanUser.toString();
        newButton.toString();
    
        function displayArrayObjects(arrayObjects,outputName) {
                    // First Check the Array Length
                    var len = arrayObjects.length, text = "";
                    this.outputName = outputName;
                   
                          //Loop through the Array

                          for (var i = 0; i ";

                      document.getElementById(outputName).innerHTML = text;

                   displayArrayObjects( newMakanUser,"outputArray");

                      }
    
// This Function is to create an object and store it inside an array.
function addName(UserName){
    // Get the User Input Object product name
       UserName = document.getElementById("NamePax").value;
                   
            TempUSer =  UserName ;    
    
         TempVar.push(new UserCustomer(UserName));
         // alert( "Hello");
      //  newMakanUser.push(new myUserName(createProduct,productprice));
       slides.style.display = "block";
       slidess.style.display = "none";
       slidesss.style.display = "none";
}
    
function addFoodPrice(Foody,Pricey){
        Foody  = document.getElementById("FoodyName").value;
        Pricey  = document.getElementById("FoodyPrice").value;
          TempVar.Food.push(Foody);
          TempVar.Price.push(Pricey);
}
    
function doneAdd(){
    
        newMakanUser.push(TempVar);
        
        slides.style.display = "none";
        slidess.style.display = "block";
        slidesss.style.display = "block";
       // document.getElementById("outputDB").innerHTML = text;
    
}

// This Function will remove the unwanted object

Who Order  the Food
  
Person Name:
    
Food Name :
    
Food Price :
Posted 12-Jan-18 16:35pm
Updated 12-Jan-18 23:03pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180920.1 | Last Updated 13 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100