...

View Full Version : too many prompts help...



disneyfan
03-07-2005, 07:18 PM
how do i keep from getting a prompt for each value entered?

<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>

Philip M
03-07-2005, 07:45 PM
Why do it the hard way?

<script language="JavaScript">
<!--
function oddEven() {
var entry=document.textForm.textBox.value;

if (/\D/.test(entry)) { /// if entry contains anything but digit(s)
alert ("Please Enter a Numeric Value."); /// the semi-colon is required
else
Mod= (entry % 2) ? "This value is odd!" : "This value is even!";
alert (Mod);
}
}

//--></script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum