Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,037
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •