Add on click same item

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandyyyy35
    New Member
    • May 2013
    • 21

    #1

    Add on click same item

    I wana know simple hint for javascript,

    as i am food order website, and if i click on same item name, the quantity of that item automatically add.

    Any hint.

    Code:
    			function insertrow(itemname, price)	
    				{
    					
    					var count = document.getElementById('hide_table').value;
    					count++;
    					document.getElementById('hide_table').value = count;
    					var totalsum = document.getElementById('hide_table').value;
    					var tableObj  = document.getElementById('table_1');
    					var row_count = (tableObj.rows.length)-1;
    					var rowObj    = tableObj.insertRow(row_count);
    					var cellObj_1   = rowObj.insertCell(0);   //name
    						cellObj_1.innerHTML   = '<input type="text" name="txt_'+count+'" id="name_'+count+'" value="'+itemname+'" class="textme"/>';	
    					var cellObj_1   = rowObj.insertCell(1);  //price
    						cellObj_1.innerHTML   = '<input type="text" name="txt1_'+count+'" id="price_'+count+'" value="'+price+'" class="textme"/>';	
    					var cellObj_1   = rowObj.insertCell(2);  //qty
    						cellObj_1.innerHTML   = '<input type="text" name="txt2_'+count+'" id="qty_'+count+'" value="" class="textme" onkeyup="game('+count+')"/>';
    					var cellObj_1   = rowObj.insertCell(3);  //total
    						cellObj_1.innerHTML   = '<input type="text" name="txt3_'+count+'" id="total_'+count+'" value="" class="textme" />';	
    					var cellObj_2   = rowObj.insertCell(4);
    						cellObj_2.innerHTML   = '<img src="close.png" width="15" height="15" onclick="rmv_item(this)"/>';
    				}
    <form method="post">
    <div class="head">
    		<span>Food Court</span>
    </div>
    <div class="table_2">
    <table>
    				<tr>
            		<td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Momo'),('50'))" value="Momo" style="border:0px; background:0"/></td>
            </tr>
            		<tr>
            		<td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Chow'),('75'))" value="Chow" style="border:0px; background:0"/></td>
            </tr>
            		<tr>
            		<td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('spring'),('35'))" value="spring" style="border:0px; background:0"/></td>
            </tr>
            		<tr>
            		<td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Roll'),('25'))" value="Roll" style="border:0px; background:0"/></td>
            </tr>
            		<tr>
            		<td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Tikki'),('15'))" value="Tikki" style="border:0px; background:0"/></td>
            </tr>
            		<tr>
            		<td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Chicken'),('110'))" value="Chicken" style="border:0px; background:0"/></td>
            </tr>
            		<tr>
            		<td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Lolipop'),('75'))" value="Lolipop" style="border:0px; background:0"/></td>
            </tr>
            		<tr>
            		<td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Noodles'),('75'))" value="Noodles" style="border:0px; background:0"/></td>
            </tr>
            		<tr>
            		<td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Maggie'),('35'))" value="Maggie" style="border:0px; background:0"/></td>
            </tr>
            		<tr>
            		<td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Hakka'),('65'))" value="Hakka" style="border:0px; background:0"/></td>
            </tr>
            </table>
    </div>
    <input type="hidden1" id="hide_table" name="hide_table" value="0" /><br />
    
    	<table id="table_1">
    		</table>
            <input type="submit" name="sub_1" id="sub_1" value="Order" onclick="rtrn_value()" /><br />
    <input type="text" name="total1" id="total1" value="" />
    </form>
  • Exequiel
    Contributor
    • Jul 2012
    • 288

    #2
    I think you must use Jquery for easy coding for that kind of problem, , , Jquery is a javascript but you need to download a package in order to used the functions of jquery. . try to search it in google or in youtube.

    Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.

    Comment

    • sandyyyy35
      New Member
      • May 2013
      • 21

      #3
      hm gud but not helped me out.

      Comment

      Working...