disneyfan
03-07-2005, 01:22 PM
I'm very new at this and trying to learn on my own. I'm going through a book I got from a friend who took a javascript class a few years ago and working on some of the example assignments. I'm having trouble (of course) and would love for someone I could email regulary that would be able to help me... or just post on here often with dumb questions :)
here's one I'm kinda stuck on right now...
I think I might have one working that checks to see if the user inputs a number and to check to see if it is odd or even. The only thing is if you enter more than 1 number it'll prompt you more than once? Any ideas?
<script language="JavaScript"><!--
function oddEven() {
var entry=document.textForm.textBox.value;
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < entry.length && IsNumber == true; i++)
{
Char = entry.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
alert ("Please Enter a Numeric Value.")
}
if (ValidChars.indexOf(Char) != -1)
{
var Mod= (entry % 2) ? "This value is odd!" : "This value is even!";
alert (Mod);
}
}
}
//--></script>
the next thing I want to do it figure out how to change that code into check to see that the user inputs a number that is 9 characters long. Is this it?
var length= (entry.length <= 9) ? "This value is less than 9!" : "This value is greater than 9!";
alert (length);
but again, the # of characters you enter equals the number of prompts you get... what am I doing wrong?
I would even be willing to pay someone a small few to help kinda tutor me when I need help with some of these examples. Once I see how they are correctly coded it begins to make sense.. just having a hard time at the beginning. PM me if interested...
here's one I'm kinda stuck on right now...
I think I might have one working that checks to see if the user inputs a number and to check to see if it is odd or even. The only thing is if you enter more than 1 number it'll prompt you more than once? Any ideas?
<script language="JavaScript"><!--
function oddEven() {
var entry=document.textForm.textBox.value;
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < entry.length && IsNumber == true; i++)
{
Char = entry.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
alert ("Please Enter a Numeric Value.")
}
if (ValidChars.indexOf(Char) != -1)
{
var Mod= (entry % 2) ? "This value is odd!" : "This value is even!";
alert (Mod);
}
}
}
//--></script>
the next thing I want to do it figure out how to change that code into check to see that the user inputs a number that is 9 characters long. Is this it?
var length= (entry.length <= 9) ? "This value is less than 9!" : "This value is greater than 9!";
alert (length);
but again, the # of characters you enter equals the number of prompts you get... what am I doing wrong?
I would even be willing to pay someone a small few to help kinda tutor me when I need help with some of these examples. Once I see how they are correctly coded it begins to make sense.. just having a hard time at the beginning. PM me if interested...