Howdy Partners,
I could use some help if someone has the time, I would really appreciate it immensely.
Concerning variables. I don't know the official way to declare a Public or Global variable. In other words, a variable that is common to say, four functions.
Also, when I use the variable across multiple functions like passing the variable to anothet function and returning a boolean.
Should I use it like such "var nextChar" or "nextChar". I've looked and looked for info but just can't seem to find any clear info.
Please help.
Here's some code I wrote and currently working on. This code does work without errors though I get a NaN when I try to validate two empty textBoxes.
Please tell me where I should do what with variables.
This takes strings from two textBoxes, validates the entries as numbers, adds the two numbers, and displays the result in a third textBox.
<script language="JavaScript">
!<--
function formFocus() {
document.myform.boxA.focus(); //gives focus to boxA on Load
document.myform.boxA.value=""; //clears boxA on Load
document.myform.boxB.value=""; //clears boxB on Load
document.myform.sum.value=""; //clears Total on Load
}
function isEmpty(hey, you) {
var hey;
var you;
if ((hey == "") || (you == ""))
{ return true; }
}
function isNumber(hey, you) {
var hey;
var you;
var valid = "0123456789";
var result = false;
for (var x=0; x < hey.length; x++) {
var charX = hey.charAt(x);
if (valid.indexOf(charX) == -1)
{ result = true;
var a = true;
document.myform.boxA.value="";
document.myform.boxA.focus();
break;
}
}
for (var x=0; x < you.length; x++) {
var charX = you.charAt(x);
if (valid.indexOf(charX) == -1)
{ result = true;
var b = true;
document.myform.boxB.value="";
document.myform.boxB.focus();
break;
}
}
if ((a == true) && (b == true))
document.myform.boxA.focus();
return result;
}
function docOpen() {
var hey = document.myform.boxA.value; //assigns value of boxA to var hey
var you = document.myform.boxB.value; //assigns value of boxA to var hey
if ( isEmpty(hey,you) == true)
{ alert('You must enter numbers in both Box 1 and Box 2'); }
if ( isNumber(hey,you) == true)
{ alert('You must enter numbers only'); }
else {
var total = parseFloat(you) + parseFloat(hey);
document.myform.sum.value= total; }
//-->
</script>
I could use some help if someone has the time, I would really appreciate it immensely.
Concerning variables. I don't know the official way to declare a Public or Global variable. In other words, a variable that is common to say, four functions.
Also, when I use the variable across multiple functions like passing the variable to anothet function and returning a boolean.
Should I use it like such "var nextChar" or "nextChar". I've looked and looked for info but just can't seem to find any clear info.
Please help.
Here's some code I wrote and currently working on. This code does work without errors though I get a NaN when I try to validate two empty textBoxes.
Please tell me where I should do what with variables.
This takes strings from two textBoxes, validates the entries as numbers, adds the two numbers, and displays the result in a third textBox.
<script language="JavaScript">
!<--
function formFocus() {
document.myform.boxA.focus(); //gives focus to boxA on Load
document.myform.boxA.value=""; //clears boxA on Load
document.myform.boxB.value=""; //clears boxB on Load
document.myform.sum.value=""; //clears Total on Load
}
function isEmpty(hey, you) {
var hey;
var you;
if ((hey == "") || (you == ""))
{ return true; }
}
function isNumber(hey, you) {
var hey;
var you;
var valid = "0123456789";
var result = false;
for (var x=0; x < hey.length; x++) {
var charX = hey.charAt(x);
if (valid.indexOf(charX) == -1)
{ result = true;
var a = true;
document.myform.boxA.value="";
document.myform.boxA.focus();
break;
}
}
for (var x=0; x < you.length; x++) {
var charX = you.charAt(x);
if (valid.indexOf(charX) == -1)
{ result = true;
var b = true;
document.myform.boxB.value="";
document.myform.boxB.focus();
break;
}
}
if ((a == true) && (b == true))
document.myform.boxA.focus();
return result;
}
function docOpen() {
var hey = document.myform.boxA.value; //assigns value of boxA to var hey
var you = document.myform.boxB.value; //assigns value of boxA to var hey
if ( isEmpty(hey,you) == true)
{ alert('You must enter numbers in both Box 1 and Box 2'); }
if ( isNumber(hey,you) == true)
{ alert('You must enter numbers only'); }
else {
var total = parseFloat(you) + parseFloat(hey);
document.myform.sum.value= total; }
//-->
</script>