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

If Else statement

347 100+
I have a page that adds up amounts assigned to checkboxes in a form and gives a total at the bottom of the page, this is done with some javascript i found as i am useless with it.

What i am tring to do is change the part of the page that is visible if the amount of the total gets above a certain amount.

this is the code that shows the totals
Expand|Select|Wrap|Line Numbers
  1. <TABLE width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  2.                    <TR>
  3.                      <TD width="50%"><DIV align="right">Total&nbsp;£
  4.  
  5.                          <INPUT name="answer" type="text" id="answer" style="border: none" value="" size="5" readonly="readonly"/>
  6.                      </DIV></TD>
  7.                      <TD width="50%"><DIV align="right">Total&nbsp;£
  8.  
  9.                        <INPUT name="answer2" type="text" id="answer2" style="border: none" value="" size="5" readonly="readonly"/>
  10.                      </DIV></TD>
  11.                    </TR>
  12.                  </TABLE>
and this is the javascript that keeps the totals with an onclick in the checkbox
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function calculate(f)
  3. {
  4. var nums = f.num;
  5. var ntext = f.num;
  6. var result = 0;
  7. for(var i=0;i<nums.length;i++)
  8. {
  9. if(nums[i].checked)
  10. {
  11. result+=parseFloat(ntext[i].value);
  12. }
  13. }
  14. f.answer.value=Number(result).toFixed(2);
  15. }
  16. </script>
  17. <script type="text/javascript">
  18. function calculate2(f)
  19. {
  20. var nums2 = f.num2;
  21. var ntext2 = f.num2;
  22. var result2 = 0;
  23. for(var i=0;i<nums2.length;i++)
  24. {
  25. if(nums2[i].checked)
  26. {
  27. result2+=parseFloat(ntext2[i].value);
  28. }
  29. }
  30. f.answer2.value=Number(result2).toFixed(2);
  31. }
  32. </script>
I am able to make something like this work with asp but dont really want to have to reload the page on every click

can anyone help

the page can be found at http://www.yaketyyakallmouth.com/rad...new/local2.asp
Dec 8 '09 #1
3 2122
Dormilich
8,658 Expert Mod 8TB
that page looks familiar………

for your HTML I recommend a six column table … much easier to read.

the idea behind the hiding is quite simple. if the condition is met (value of totals field > treshold) change CSS of the element.
Expand|Select|Wrap|Line Numbers
  1. function enough()
  2. {
  3.     // using a random treshold of 1,000
  4.     if (1000 < this.value)
  5.     {
  6.         // change the style of the element to hide
  7.         document.getElementById(…).style.visibility = "hidden";
  8.     }
  9. }
  10. document.getElementById("answer").addEventListener("change", enough, false);
  11. // you can also use addEvent() to be IE-compatible
Dec 8 '09 #2
colinod
347 100+
cant get this to work get an error
'document.getElementById(...)' is null or not an object

i have replaced the (...) with the id of the text i want to change to ("text")

any ideas
Dec 11 '09 #3
Dormilich
8,658 Expert Mod 8TB
'document.getElementById(...)' is null or not an object
obviously…

since I’m not familiar with your source code (I take a look at it only from time to time) you have to add the appropriate id values yourself.

further, there is a good reason I use addEventListener(), you can’t accomplish the same with inline JavaScript (like <a … onclick="myfunc()">).
Dec 12 '09 #4

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

Similar topics

11
by: dmbkiwi | last post by:
I am new to this group, and relatively new to python programming, however, have encountered a problem I just cannot solve through reading the documentation, and searching this group on google. I...
27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
3
by: Patrice | last post by:
Hi, I need to do multi-conditional statements like below, but this error is displayed : Expected 'End' /myFilepath, line x else response.write(arrCorpo(sparam,sdiv)) end if I don't...
6
by: Karen Middleton | last post by:
In MS Access I can do in one SQL statement a update if exists else a insert. Assuming my source staging table is called - SOURCE and my target table is called - DEST and both of them have the...
12
by: Roman Töngi | last post by:
In c++ there does not exist an if-statement as for example in Visual Basic, does it? //VB-analogy: if (cond.) statement; else if (cond.) statement; else statement;
5
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to...
18
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
3
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the...
2
by: paul | last post by:
Hi all, I've been handed some code and, unless I've got the numbering of parentheses wrong, one of the functions has a curious if-else statement. The thing compiles but is it right? I know the...
20
by: John Salerno | last post by:
I'm starting out with this: try: if int(text) 0: return True else: self.error_message() return False except ValueError: self.error_message()
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.