473,325 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

how can I sum the price of the item that I selected from my dropdown that retrieved i

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     //database connection here
  3. ?>
  4. <table class = "TOTAL" border =" 1">
  5.  
  6.     <thead>
  7.         <tr>
  8.             <th>Component</th>
  9.             <th>Item Name   </th> 
  10.             <th>Price </th>  
  11.  
  12.         </tr>
  13.     </thead>
  14.     <tbody>
  15.         <tr>
  16.             <td>CPU</td>
  17.             <td>
  18.                 <?php
  19.                 //Retrieving CPU table
  20.                     $query = $conn->query("SELECT * FROM cpu");
  21.                         echo '<select  onChange = parseFloat($("#cpuprice").val($(this).find("option:selected").attr("cpuprice")))>';
  22.                         echo "<option>---select your CPU---</option>";
  23.                             while ($obj = $query->fetch_object()){
  24.                                 echo '<option cpuprice = "'.$obj->price.'" >'.$obj->cpuname.'</option>';                                
  25.                             }
  26.                         echo '</select>';
  27.                 ?>                                                 
  28.             </td>
  29.             <td>
  30.             <output id="cpuprice" disabled value="">    
  31.             </td>
  32.         </tr>   
  33.     </tbody>                            
  34.     <tbody>
  35.         <tr>
  36.             <td>GPU</td>
  37.             <td>
  38.                 <?php
  39.                 //Retrieving GPU table
  40.                     $query = $conn->query("SELECT * FROM gpu");
  41.                         echo '<select  onChange = parseFloat($("#gpuprice").val($(this).find("option:selected").attr("gpuprice")))>';
  42.                         echo "<option>---select your GPU---</option>";
  43.                             while ($obj = $query->fetch_object()){
  44.                                 echo '<option  gpuprice = "'.$obj->price.'" >'.$obj->gpuname.'</option>';                               
  45.                             }
  46.                         echo '</select>';
  47.                 ?>                                     
  48.             </td>
  49.             <td>
  50.             <output id="gpuprice" disabled value="">    
  51.             </td>
  52.         </tr>   
  53.     </tbody>
  54.     <tbody>
  55.         <tr>
  56.             <td></td>
  57.             <td>                                    
  58.             </td>
  59.             <td>
  60.                 <span class="totalprice">Total: </span>
  61.                 <script> 
  62.                         // i tried this but it always return NaN after selecting an item
  63.                     $('select').change(function() {     
  64.                         var total = 0;                          
  65.                         var cpu = parseInt($(total).val($(this).find("option:selected").attr("cpuprice")))
  66.                         var gpu = parseInt($(total).val($(this).find("option:selected").attr("gpuprice")))
  67.                         total = parseInt(cpu) + parseInt(gpu);
  68.                     $('.totalprice').text('₱'+ total);                       
  69.                     })
  70.                 </script>                 
  71.             </td>
  72.         </tr>   
  73.     </tbody>
  74. </table>
Attached Images
File Type: png af.png (9.2 KB, 45 views)
Dec 9 '20 #1
0 2258

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

Similar topics

1
by: Andy Fish | last post by:
Hi, Part of my web form allows the user to select their favourite color (well it doesn't but it's a good example). There is a dropdown box with red, green, blue, and custom. When they click...
2
by: hypomite | last post by:
I have an handler for the SelectedIndexChanged event of a dropdown box. I have also set the AutoPostBack option to True. When you select any item besides the first one, the event sucessfully fires....
3
by: Big Dave | last post by:
I know it's been asked a million times before, but I still can't seem to find an answer that works. I've got a dropdown list in the footer template of a datagrid. The dropdown list databinds,...
1
by: Rudy Ko | last post by:
Hi, I seem unable to set the selected item in a DropDownList by using the following code, it always return the toppest (index 0) item, no matter what i selected. list.DataSource =...
1
by: dev.amit | last post by:
Hello friends Can anyone tell me how to deselect the item selected in the list box If Me!lb_test_property.ItemsSelected.Count > 0 Then For Each varItem In Me!lb_test_property.ItemsSelected...
1
by: imran | last post by:
Dear All, I am developing web Application using asp.net and C#(VS2005).i want to know how i can fetch menu item selected(which is desinged in master.aspx) on the other C# page (welcome.aspx.cs).
0
by: lalit | last post by:
Can some one please tell me how to make a specuific item selected in dropdwonlist my dropdwonlist is bounded with a database table getting something like this: <tr> <td > Client Name</td> <td...
4
by: coldfusionstudent | last post by:
i wish to show/appear and dissappear text box based on a the drop down item selected. what do i have to add? thanks under Comm_DEV drop down selection.
0
by: yashpal22 | last post by:
How to hide selected item in dropdown in other dropdown?in c#
1
by: ewalsh9898 | last post by:
while processing the items in a listbox foreach loop, the if (item.selected) never finds expected row(s) The foreach is looping thru the data as expected. <asp:ListBox runat="server"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.