473,396 Members | 1,968 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.

how to get the total

I have two inputs box in PHP and I wanted to add third box to get the total. Originally the code will fetch if there's a current value on the table, other wise the third box will compute whatever number are there in my two boxes.

Expand|Select|Wrap|Line Numbers
  1. echo "Value1";
  2. $result = mysql_query("select Total from tbl1 where ID='{$id}' ");    $row = mysql_fetch_assoc($result);
  3. $Total1 =  $row['Total'];
  4.  
  5. echo "Value2";
  6. $result = mysql_query("select Total from tbl2 where ID='{$id}' ");    $row = mysql_fetch_assoc($result);
  7. $Total2=  $row['Total'];            
  8.  
  9. //from here i dont know how to compute the sum of the two        
  10. ehco "Total Value" <input type='text'  value=$Total1+Total2>
  11.  
Oct 9 '09 #1
7 2137
TheServant
1,168 Expert 1GB
@mychikka
1. You misspelled echo.
2. You have html out of the string, so Total Value is a string and all that follows php will attempt to run as PHP, but it's not so you will get an error.

Try:
Expand|Select|Wrap|Line Numbers
  1. $total = $Total1+$Total2;
  2. echo "Total Value: <input type='text' value='$total' />";
Hope that helps.
Oct 9 '09 #2
How can I make the text box to do automatic calculation everytime the user changes the input box total?

@TheServant
Oct 9 '09 #3
Dormilich
8,658 Expert Mod 8TB
@mychikka
does that have anything to do with your PHP code? (your values came from DB…)
Oct 9 '09 #4
HI Dormilich... but sometimes the user input value on the text box if the value is zero. Actually my goal here is to have a pop-up message box if its over a 100 in total.

I think i need your help to place this on java script section.

thanks!
Oct 9 '09 #5
Dormilich
8,658 Expert Mod 8TB
[[ moving to Javascript Forum ]]

that depends on which values you want to add (or rather, how you can access them)
Oct 9 '09 #6
anybody can show me how to this?

the value will be coming from my PHP form
Expand|Select|Wrap|Line Numbers
  1. $total = $Total1+$Total2; 
  2. echo "Total Value: <input type='text' value='$total' />"; 
when the user hit the save button it will pop a message alert if the total is over 100.


Please advice.
Oct 9 '09 #7
Dormilich
8,658 Expert Mod 8TB
provided you make the elements accessible (using an id)
Expand|Select|Wrap|Line Numbers
  1. // save button
  2. var save = document.getElementById("save");
  3. // total field
  4. var total = document.getElementById("total");
  5. // define the popup
  6. var popup = function()
  7. {
  8.   if (total.value > 100)
  9.   {
  10.     alert("value too big!");
  11.     total.focus();
  12.   }
  13. }
  14. // define the event
  15. // google for the addEvent() function
  16. addEvent(save, "click", popup, false);
Oct 9 '09 #8

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

Similar topics

1
by: beavenour | last post by:
I am looking for some help creating a more universal function out of this lame attempt at javascript. I have little experience with javascript and want to be able to universalize this function. ...
4
by: James Greig | last post by:
hello people, i'm just learning javascript, could someone point me in the direction of an example of the following, or give me some clues as to how it might be done: what i would like to do...
10
by: giancarlodirisioster | last post by:
Can someone help me modify this for future Usenet archival and to help me solve what I don't know? <form name="addform" method="POST" action="./submit.php"> <input type="text" name="Box 1"...
2
by: worli | last post by:
Hi All, I have a strange requirement. I have a dynamic input numeric data stream e.g. 2, 2, 4, 5 etc.... ( each input number range from 1 to 10 ). lets take a simple case where all inputs will...
4
by: Rich_C | last post by:
I'm sure this is very simple, but I have very little experience with javascript -- and what I do know isn't helping me here. I have a simple form where users can enter a quantity (qty) and cost...
1
by: CaptainDahlin | last post by:
I know the basics about access reports and putting page totals in the page footers. What I can't figure out is along with the current page total to display the previous page total: At the bottom...
2
by: sammiesue | last post by:
Hi, I have form with 2 autosummed textboxes ("total" and "casinototal"). I would like to have a grand total textbox ("grandtotal") get its value from summing "total" and "casinototal", but it...
6
by: Stuart Shay | last post by:
Hello All: I have a array which contains the totals for each month and from this array I want to get a running total for each month decimal month = new decimal; month = 254; (Jan) month =...
15
klarae99
by: klarae99 | last post by:
I am working on an Inventory Database in Access 2003. I am working on a report that I could print when its time to file our State Sales Tax paperwork. The figures I need for this report are Total...
21
beacon
by: beacon | last post by:
Hello to everybody, I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know),...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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.