CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 Calling all Javascript experts

Print topic Send  topic

Author Message
creed

Posts: 1
Posted: 08/22/2004, 9:46 AM

Hey all

I've been racking my brain tryign to figure out why this not only doesnt work, but doesnt even return an error message in any web browser that I've tried. Here's the code:

  
<html>  
  
<head>  
  
<script language="JavaScript"><!--  
//defines input as an integer  
function isInteger(value) {  
  return (parseInt(value) == value);  
}  
  
var integer = /^\d+$/;  
  
function validate(form) {  
//validates the input as a nine digit integer, all else is denied  
  var stockNumber = '';  
  var output = '';  
  
    
  if (!isInteger(form.myField.value)) {  
    output = 'Entry must be a number\n';  
	alert(output);  
	form.myField.focus();  
	return(false);  
  }  
  
  if (form.myField.value.length!=9) {  
	output = 'Entry must be nine digits long\n';  
	alert(output);  
	form.myField.focus();  
	return(false);  
  }  
  
stockNumber = form.myField.value;  
  
//collect numbers needed for operation into arrays  
  
var firstArray = new Array(5);  
var secondArray = new Array(5);  
var thirdArray = new Array(4);  
  
firstArray[0] = stockNumber.charAt(0);  
firstArray[1] = stockNumber.charAt(2);  
firstArray[2] = stockNumber.charAt(4);  
firstArray[3] = stockNumber.charAt(6);  
firstArray[4] = stockNumber.charAt(7);  
  
thirdArray[0] = stockNumber.charAt(1);  
thirdArray[1] = stockNumber.charAt(3);  
thirdArray[2] = stockNumber.charAt(5);  
thirdArray[3] = stockNumber.charAt(7);  
  
fArrayResult = 0;  
arrayTotal = 0;  
  
//if fArrayResult is larger than 9, parse the two numbers, add together, and store in secondArray, otherwise, just store in second array  
for (var i = 0; i <= 4; i++) {  
 fArrayResult = firstArray * 2;  
   	if (fArrayResult > 9) {  
		firstNum = fArrayResult.charAt(0);  
		secondNum = fArrayResult.charAt(1);  
		secondArray = firstNum + secondNum;  
		}  
	else {secondArray = fArrayResult;};  
	}  
	  
//add all numbers together from both second and third array  
total = secondArray[0] + secondArray[1] + secondArray[2] + secondArray[3] + secondArray[4] + thirdArray[0] + thirdArray[1] + thirdArray[2] + thirdArray[3];  
  
//if the total is either 0, or the second number is 0, define check digit as 0, otherwise check digit is 10-second digit  
if (total == 0) {  
	alert('Check digit is 0');  
	}  
else if (total.charAt(1) == 0) {  
	alert('Check digit is 0;');  
	}  
else { newTotal = 10 - total.charAt(1);  
	alert(newTotal);  
	}  
}  
  
//--></script>  
  
</head>  
  
<body>  
  
<form onsubmit="return validate(this)">  
<input type="text" name="myField">  
<input type="submit" value="Submit">  
</form>  
  
</body>  
  
</html>  
/
  
  
As you can see it's supposed to take a nine digit number, validate it, and find a certain combination based on the operations that i've tried to specify. for example, if you typed in 987654321, it shoudl return 7.   
  
Any help on what's going wrong ehre would be appriciated. 
                   
View profile  Send private message
rbaldwin

Posts: 172
Posted: 08/24/2004, 9:18 AM

You might want to look at the statement:
fArrayResult = firstArray * 2;

I don't think you want to multiply an array by an integer?

and secondArray isn't being populated as you think it is.
Do an alert(total) just after you add the numbers from the 2 arrays togeather.

View profile  Send private message
Maruf
Posted: 09/11/2004, 9:22 AM

Your isInterger function will always return false, as you are trying to dp parseInt(value) = value, where RHS value is an string, no matter what you really have as value.

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.