JuniorBee
asked on
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.
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.
ASKER
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;
}
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;
}
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.
ASKER
I did post the code above =)
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
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
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").v alue >= 1 && document.getElementById("a mount").va lue <= 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)">
function check(frm)
{
if (document.getElementById("
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)">
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<head>
<script language="JavaScript">
function check()
{
if (document.getElementById("
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