473,396 Members | 1,877 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,396 software developers and data experts.

get total for selected record every time when checking checkbox using JavaScript

Expand|Select|Wrap|Line Numbers
  1. <div style="background-color:#fffcc0; font-family:Arial, Helvetica, sans-serif; color:#000000; padding:5px; margin:auto; width:400px; height:auto;"> 
  2. <?php
  3. $con = mysql_connect("localhost","root","");
  4. if (!$con)
  5. {
  6. die('Could not connect: ' . mysql_error());
  7. }
  8.  
  9. mysql_select_db("studentrecord", $con);
  10.  
  11. $result = mysql_query("SELECT * FROM miscellaneous");
  12.  
  13.  
  14.  
  15. while($row = mysql_fetch_array($result))
  16. {
  17. echo "<tr>";
  18. echo "<th scope='row' class='spec'>" . '<input name="selector[]" type="checkbox" value="'.$row['Misc_Code'].'">' . "</th>";
  19. // echo "<th scope='row' class='spec'>" . '<input name="selector[]" type="checkbox" value="'.$row['Misc_Code'].'">' . "</th></br>";
  20. echo "&nbsp;&nbsp;<td>" . $row['Misc_Code'] . "</td></br>";
  21. echo "</tr>";
  22. }
  23. echo "</table>";
  24.  
  25. mysql_close($con);
  26. ?>
  27. </div>
Feb 4 '13 #1
4 1894
Dormilich
8,658 Expert Mod 8TB
since you posted in the JavaScript forum, what’s with all those PHP code?
Feb 4 '13 #2
i want to use some javascript code so that every time when i check some record it will automatically get the total value of the selected record...pls help
Feb 4 '13 #3
Anas Mosaad
185 128KB
Please note that th tag is used to add table header. You are not supposed to use it for table data. You should use td instead.

Regarding JS, adding to Dormilich say: what is your JS problem to help you in? We are not supposed to give you help with a complete solution without especially if you don't start helping yourself first. Give it a try and if you get stuck, post and we will see how we can help.
Feb 4 '13 #4
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function checkTotal() {
  3. document.listForm.total.value = '';
  4. var sum = 0;
  5. for (i=0;i<document.listForm.choice.length;i++) {
  6. if (document.listForm.choice[i].checked) {
  7. sum = sum + parseInt(document.listForm.choice[i].value);
  8. }
  9. }
  10. document.listForm.total.value = sum;
  11. }
  12. </script>
  13.  
  14. <form name="listForm">
  15. <input type="checkbox" name="choice" value="2" onchange="checkTotal()"/>2<br/>
  16. <input type="checkbox" name="choice" value="5" onchange="checkTotal()"/>5<br/>
  17. <input type="checkbox" name="choice" value="10" onchange="checkTotal()"/>10<br/>
  18. <input type="checkbox" name="choice" value="20" onchange="checkTotal()"/>20<br/>
  19. Total: <input type="text" size="2" name="total" value="0"/>
  20. </form>
-----------------------------------------------
instead of the value above, now i want that value coming from mysql database. This is my code below getting record from sql

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7.  
  8. mysql_select_db("studentrecord", $con);
  9.  
  10. $result = mysql_query("SELECT * FROM miscellaneous");
  11.  
  12.  
  13.  
  14. while($row = mysql_fetch_array($result))
  15. {
  16. echo "<tr>";
  17. echo "<th scope='row' class='spec'>" . '<input name="selector[]" type="checkbox" value="'.$row['Misc_Code'].'">' . "</th>";
  18.  
  19. echo "&nbsp;&nbsp;<td>" . $row['Misc_Amount'] . "</td></br>";
  20. echo "</tr>";
  21. }
  22. echo "</table>";
  23.  
  24. mysql_close($con);
  25. ?>
Feb 5 '13 #5

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

Similar topics

1
by: Ramakrishnan Nagarajan | last post by:
Hi, I have two checkboxes in each row of a grid. One for Modify and another one for View. If I click Modify the View should get automatically checked and should be disabled. Earlier I did this in...
3
by: tom-co | last post by:
Hi. I am using this code so that when a checkbox is selected it populates two separate textfields with the word "No". <script type="text/javascript"><!-- function setField(what) { if...
0
by: Lotta P | last post by:
Hi, I have a problem concerning encoding when posting a form. The form (a textbox and a button) is posted using JavaScript and a window.location("http://therecieverofthedata"). The website...
1
by: jatrojoomla | last post by:
Hi, I am New in JS world, I want's to submit a from using JavaScript ? is it possible? if yes then how? how to impliment document.form.submit? plz help me.
2
by: simon.wilkinson | last post by:
Hi, I am trying to update all Select boxes on a page dynamically using javascript, I simple want to change the selected item in each select box when a tick box is pressed on the page. Each...
2
by: AmitKu | last post by:
<script> function CheckChange() { var mycheck = document.getElementById('test'); mycheck.check = true; } </script> <body> <form id="form1" runat="server">
1
by: Amar | last post by:
Hi All, In my php application , I am using an sql query and this query is returning me a now of rows and I am storing these values in check box. Here I am using a single check box and...
1
by: Sirisha | last post by:
Hi, I want javascript for displaying multiple textboxes dynamically. ADD-this is button. if i click button first time it will display 1 textbox and if i click 2nd time it will display another...
6
by: Peter Afonin | last post by:
Hello, I'm creating an application in ASP.NET 1.1. I need to check whether at least one checkbox in my datagrid has been checked. To do this, I'm using Javascript - I'm adding this code to...
1
by: vivek kapile | last post by:
Title:Dynamically adding table row with a checkbox using JavaScript Author:Vivek Kapile Email:snipped Language:JavaScript Platform:JavaScript in ASP.net Technology:Used in ASP.net...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.