Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-07-2005, 06:18 PM   PM User | #1
disneyfan
New Coder

 
Join Date: Mar 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
disneyfan is an unknown quantity at this point
too many prompts help...

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>
disneyfan is offline   Reply With Quote
Old 03-07-2005, 06:45 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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>
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:26 AM.


Advertisement
Log in to turn off these ads.