Check form field for integer betwen 1 and 5000

I have a form field called 'amount'.  When the form is submitted, I need to check to make sure that it contains an integer equal to or greater than 1 and that it's not more than 5000.

I tried using the built in form field valiation in Frontpage, but it messed up my other javascript functions on the page somehow so I can't use that.
JuniorBeeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nabsolCommented:
Hope this helps!

<head>
<script language="JavaScript">
function check()
{
   if (document.getElementById("amount").value >= 1 && document.getElementById("amount").value <= 5000){
        return true;
    }
    else{
       alert("Enter Between 1 and 5000")
       return false;
    }
       
}
</script>
</head>
<body>
<form onsubmit="return check()">
<input id="amount" type="text" size="5">
<input type="submit" value="submit">
</form>
<body>

By Nab
0
JuniorBeeAuthor Commented:
Super great!

But it messes up my button.  I have a button (2 buttons) that go disabled after clicking to submit.
When I enter an invalid number and submit the form, the alrt pops up and says "Enter Between 1 and 5000", but my buttons are disabled so I cannot submit the form again :(

I tried working in something to couteract the disabled function but I am not so good at javascript syntax.  Here is the function, do you think you could help me make the button not disabled it the alert box pops up?
 =) Thx

function disable(f) {
    var button = f.elements['WithdrawButton'];
    button.value = 'Processing';
    button.disabled = 'true';
    return true;    
}

function disable2(f) {
    var button = f.elements['Cancel'];
    button.value = 'Cancel';
    button.disabled = 'true';
    return true;    
}
0
nabsolCommented:
What do u do. You have two buttons and you are calling these two functions when they are clicked. Can you post some code here.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

JuniorBeeAuthor Commented:
I did post the code above =)
0
nabsolCommented:
I wonder how      button.disabled = 'true'     is working.   You have to write      button.disabled = true  

Anyway so if you don't want to disable your buttons then REMOVE this line::    button.disabled = true;      
or if you want to enable any button use :      button.disabled = false;


So button.disabled = true for disabling and  button.disabled = false for enabling :-)



By Nab
0
smaccariCommented:
Just suppress your call to your functions in the onclick of your submit (i suppose that the call is made there), and modify nabsol's function as this:

function check(frm)
{
   if (document.getElementById("amount").value >= 1 && document.getElementById("amount").value <= 5000){
        disable(frm);
        disable2(frm);
        return true;
    }
    else{
       alert("Enter Between 1 and 5000")
       return false;
    }
       
}

And the call to this function in the form element:


<form onsubmit="return check(this)">
0
mvan01Commented:
To be sure that the value is a number, and an integer, you may wish to do this:

var i = parseInt(document.getElementById("amount").value);         // returns a number - an integer
var f = document.getElementById("amount").value*1;                    // returns a floating point number, same as parseFloat(...) would, but it's easier
if (isNaN(i) || i != f) {
  alert ('Please enter an integer value only');
  return false;
}

and then continue in nabsol's or smaccari's function, with your compare, thus:

if (1<=i && i <= 5000) {

Peace and joy.  mvan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.