Problem in adding name of product to div on clicking add button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • layerex
    New Member
    • Feb 2012
    • 1

    Problem in adding name of product to div on clicking add button

    i having a problem in this code.. i want is when i click the add button it will be see the name of the product in the this box will change. im using a array .

    because im making a online ordering :)

    can u help me thanks for the advance

    Code:
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script language="javascript" type="text/javascript">
    	var add = new Array;
    	var sub = new Array;
    	var ctr = 0;
    	var bilang=0;
    	document.budget.quantity.value=bilang;
          function compute(ope)
    		{
    			if(ope == "add")
    			{
    				bilang+=1;
    				document.budget.quantity.value=bilang;
    			}
    			else if(ope == "sub"){
    				if (bilang == 0)
    				{
    					document.budget.quantity.value=0;
    				}
    				else
    				{
    					bilang -=1;
    					document.budget.quantity.value=bilang;
    				}
    			}
    		}
    	var items = new Array();
    	function addItem() 
    	{
    		var theItem = document.getElementById('the_list').value;
    		var str = '';
    		items.push(theItem);
    		for(var i=0; i<items.length; i++) 
    		{
    			str += items[i]+', ';
    		}
    		document.getElementById('the_output').innerHTML = str;
    	}
        </script>
    </head>
    <body>
      <div id="the_output">this box will change</div>
      <form name = budget>
      <img src = sample.png>
      <input type = "text" name = "the_list" value = "Pencil" readonly = "readonly">
      Price: <input type = "text" name = "Prices" value = "10"> <br/>
      Quantity: <input type=text name=quantity readonly = "readonly"><br/>
    	<input type = "button" value = "+" onClick = "compute('add')">
    	<input type = "button" value = "-" onClick = "compute('sub')">	<br>
      <input type = button value = "Add" onclick = "addItem();">
      
      </form>
    </body>
    </html>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Check the error console.

    You have a number of errors, e.g. attempting to access by ID when no ID is defined, trying to access element before it's defined/available.

    Comment

    Working...