By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,067 Members | 1,849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,067 IT Pros & Developers. It's quick & easy.

Add on click same item

P: 21
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.

Expand|Select|Wrap|Line Numbers
  1.             function insertrow(itemname, price)    
  2.                 {
  3.  
  4.                     var count = document.getElementById('hide_table').value;
  5.                     count++;
  6.                     document.getElementById('hide_table').value = count;
  7.                     var totalsum = document.getElementById('hide_table').value;
  8.                     var tableObj  = document.getElementById('table_1');
  9.                     var row_count = (tableObj.rows.length)-1;
  10.                     var rowObj    = tableObj.insertRow(row_count);
  11.                     var cellObj_1   = rowObj.insertCell(0);   //name
  12.                         cellObj_1.innerHTML   = '<input type="text" name="txt_'+count+'" id="name_'+count+'" value="'+itemname+'" class="textme"/>';    
  13.                     var cellObj_1   = rowObj.insertCell(1);  //price
  14.                         cellObj_1.innerHTML   = '<input type="text" name="txt1_'+count+'" id="price_'+count+'" value="'+price+'" class="textme"/>';    
  15.                     var cellObj_1   = rowObj.insertCell(2);  //qty
  16.                         cellObj_1.innerHTML   = '<input type="text" name="txt2_'+count+'" id="qty_'+count+'" value="" class="textme" onkeyup="game('+count+')"/>';
  17.                     var cellObj_1   = rowObj.insertCell(3);  //total
  18.                         cellObj_1.innerHTML   = '<input type="text" name="txt3_'+count+'" id="total_'+count+'" value="" class="textme" />';    
  19.                     var cellObj_2   = rowObj.insertCell(4);
  20.                         cellObj_2.innerHTML   = '<img src="close.png" width="15" height="15" onclick="rmv_item(this)"/>';
  21.                 }
  22. <form method="post">
  23. <div class="head">
  24.         <span>Food Court</span>
  25. </div>
  26. <div class="table_2">
  27. <table>
  28.                 <tr>
  29.                 <td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Momo'),('50'))" value="Momo" style="border:0px; background:0"/></td>
  30.         </tr>
  31.                 <tr>
  32.                 <td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Chow'),('75'))" value="Chow" style="border:0px; background:0"/></td>
  33.         </tr>
  34.                 <tr>
  35.                 <td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('spring'),('35'))" value="spring" style="border:0px; background:0"/></td>
  36.         </tr>
  37.                 <tr>
  38.                 <td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Roll'),('25'))" value="Roll" style="border:0px; background:0"/></td>
  39.         </tr>
  40.                 <tr>
  41.                 <td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Tikki'),('15'))" value="Tikki" style="border:0px; background:0"/></td>
  42.         </tr>
  43.                 <tr>
  44.                 <td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Chicken'),('110'))" value="Chicken" style="border:0px; background:0"/></td>
  45.         </tr>
  46.                 <tr>
  47.                 <td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Lolipop'),('75'))" value="Lolipop" style="border:0px; background:0"/></td>
  48.         </tr>
  49.                 <tr>
  50.                 <td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Noodles'),('75'))" value="Noodles" style="border:0px; background:0"/></td>
  51.         </tr>
  52.                 <tr>
  53.                 <td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Maggie'),('35'))" value="Maggie" style="border:0px; background:0"/></td>
  54.         </tr>
  55.                 <tr>
  56.                 <td><input type="button" name="butt_2" id="butt_2" onclick="insertrow(('Hakka'),('65'))" value="Hakka" style="border:0px; background:0"/></td>
  57.         </tr>
  58.         </table>
  59. </div>
  60. <input type="hidden1" id="hide_table" name="hide_table" value="0" /><br />
  61.  
  62.     <table id="table_1">
  63.         </table>
  64.         <input type="submit" name="sub_1" id="sub_1" value="Order" onclick="rtrn_value()" /><br />
  65. <input type="text" name="total1" id="total1" value="" />
  66. </form>
  67.  
  68.  
Sep 25 '13 #1
Share this Question
Share on Google+
2 Replies


Exequiel
100+
P: 287
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.

https://www.google.com.ph/?gws_rd=cr...query+tutorial
Sep 26 '13 #2

P: 21
hm gud but not helped me out.
Sep 30 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.