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

Input String, return Number to test null?

I have a problem with my current code. I am trying to test the number for null and if it is, it will cancel my loop. It seems to cancel with the current way i have it, but i need the number to add up with the previous one each time it loops. How can i test for null to cancel, while getting my number to add up?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <script type="text/javascript"> 
  4.  
  5.     function nameInput() {
  6.     var nameIn; 
  7.         nameIn = prompt("Enter the Employees name.");
  8.  
  9.         while(nameIn !== null &&(!isNaN(nameIn) || nameIn=="")) {
  10.  
  11.  
  12.         alert("Name cannot be Blank.\n must contain only LETTERS");
  13.         nameIn =prompt("Try again, Enter the employees name.");
  14. }    
  15.  
  16.     return nameIn;    
  17. }
  18.  
  19.         function hoursInput() {
  20.  
  21.  
  22.     var numIn=prompt("Enter the Hours worked for the Week");
  23.  
  24.         while(numIn !== null && (isNaN(numIn) || numIn=="")) {
  25.  
  26.  
  27.         alert("Hours cannot be Blank.\n must contain only NUMBERS.");
  28.  
  29.         numIn=prompt("Try again, Enter the Hours worked for the Week");
  30.  
  31.     }
  32.  
  33.     return numIn;    
  34. }
  35.  
  36. </script>
  37. </head>
  38. <body>
  39. <script type="text/javascript">
  40.  
  41. // DECLARATION
  42. var wage =10;
  43. var totalHours=0;
  44. var totalEarnings=0;
  45. var    Earnings;
  46.  
  47. // PROCESSING LOOP
  48. var howMany = parseFloat(prompt(" How many employees are you inputting?", ""));
  49.  
  50. for (var loopControl = 1; loopControl <= howMany; ++loopControl) {
  51.  
  52.     var nameth=nameInput();
  53.         if(nameth==null){
  54.             break;
  55. }
  56.  
  57.     var hour=hoursInput();
  58.  
  59.         if(hour==null){
  60.             break;
  61. }
  62.  
  63.             Earnings = hour * wage;
  64.             totalHours+=hour
  65.             totalEarnings+=Earnings;
  66.  
  67.             document.write("Name of employee. "   + nameth + "<br /br>");
  68.             document.write("This employee worked. "  + hour + "<br /br>" + "<br /br>");
  69.  
  70. }
  71.  
  72. // OUTPUT
  73.  
  74. document.write("compiled Earnings is: " + totalEarnings + " " + "<br /br>");
  75. document.write("total amount of hours from all employees listed are: " + totalHours + " " + "<br /br>");
  76.  
  77. </script>
  78. </body>
  79. </html>
Nov 12 '13 #1
0 1050

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

Similar topics

2
by: Tom | last post by:
I'm trying to find a good, solid function that sanitizes string values for form validation. The user notes on php.net offer the following: ...
2
by: Jim | last post by:
im using asp.net, C# to enter data into a table in sql server...however im getting this error: Input string was not in a correct format. Description: An unhandled exception occurred during the...
9
by: nsj | last post by:
I am working with a web applicaction that accesses a SQL Server database. I need the value of the 'id' column of the last inserted row in the table 'PERSON'. The SQL statement for that purpose is:...
0
by: phmyhn | last post by:
I have two web pages, one is viewlarger.aspx, another one is shoppingcart.aspx. On the viewlarger.aspx, when clicking "add to cart" image button, the sub appends the id (passed from another page...
1
by: John Chorlton | last post by:
I've been attempting to pass a chunk of data back from a child Windows form using public properties on the form and have been getting some odd errors. I wanted to return a row of data to avoid...
8
by: Ottar | last post by:
I have a few numeric fields, and when I update i get the error: "Input string was not in a correct format". Next line:" System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&...
1
by: amitbadgi | last post by:
I am gettign this error, while migration an app to asp.net Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 19: Dim enddate =...
13
by: Jen | last post by:
One user of my application is experiencing an exception "input string not in correct format". But it makes no sense where it is occurring. It is occurring when a string from a textbox ("172") is...
0
by: sehguh | last post by:
Hiya Folks, I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005. The main page consists of an aspx page and a master page. The page also...
9
by: seep | last post by:
hi i m finding following error on the code that i wants to use to get all record from table via store procedure with paging. the error is : Input string was not in a correct...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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,...
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...

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.