Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:58:57+00:00 2026-06-03T05:58:57+00:00

I have a simple form, which performs a calculation when a digit is pressed,

  • 0

I have a simple form, which performs a calculation when a digit is pressed, however this should only happen when numbers are typed, if a letter is added i would like for a notification to appear. Is there a simple function to do this?

Form

    <input onKeyPress="return onlyNumbers()" onKeyUp="calc()" id="value1" type="text" name="value1">
    <select onChange="calc()" id="manipulator" name="manipulator">
        <option value="commission">Commission</option>
        <option value="cost">Return</option>
    </select>
</form>

calc function

function calc(){
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    } else {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    val1 = document.getElementById("value1").value;
    mani = document.getElementById("manipulator").value;

    if (val1 != ""){
        document.getElementById("resp").innerHTML="Calculating...";
        queryPath = "comCalcServ.php?value1="+val1+"&manipulator="+mani;

        xmlhttp.onreadystatechange=function(){
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                document.getElementById("resp").innerHTML=xmlhttp.responseText;
            }
        }

        xmlhttp.open("GET",queryPath);
        xmlhttp.send();
    }
}

I am currently looking at the isNaN function but not familiar with the JS syntax so unsure where to use it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:58:58+00:00Added an answer on June 3, 2026 at 5:58 am

    Do you mean:

    
    //add inside your calc function
    val1 = document.getElementById("value1").value;
    if(/^\d+$/.test(val1)) {
     //proceed with rest of code
    }
    else {
     alert("Invalid");
     return false;
    }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple form like this which accepts only two values string action and
I have written a simple CRUD form which has one select list. However the
I have an ajax form in asp.net mvc which is as simple as this:
I have a simple modal form which I'd like to close when Esc is
I have a simple Ruby on Rails form which includes an authenticity_token. Unfortunatly, I
I have a simple MVC form with the following elements: <%= Html.TextBox(FechaInicio) %> Which
Have a simple form (only extract fields here) but for some reason the JQserilization
I have a simple form which uses a queryset that is set dynamically: class
I have a simple form which is inside IFRAME. When user click on SUBMIT,
I have a simple HTML form which consists of radio buttons where user has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.