Skip to main content
Inspiring
September 29, 2008
Question

javascript to validate a percentage

  • September 29, 2008
  • 2 replies
  • 2125 views
Hello,

Any one knows a way to vaidate that the number entered in text box is either a 1 or a percent. I have been trying to validate this using javascript and its not working.

Please help
This topic has been closed for replies.

2 replies

tclaremont
Inspiring
September 29, 2008
How about trying something along these lines (I am typing from memory, so do a little bit of homework on the cfinput and the range features)...

<cfinput type="Text" name="InputField" range=".00, 1.00001">
Inspiring
September 29, 2008
What did you try and in what way did it not work?
umuayoAuthor
Inspiring
September 29, 2008
I have put <cfinput> validate as a float, that took care of that problem. But now when I validate with the regular script, it does not return back to the error form. Did I mention that this is flash forms..
See code below..

<cfsavecontent variable="Test">
var varExpressedAs = displayid.value;
var blnGreaterZero = (rangefloor.text >0)&&(rangeceiling.text >0)
var blnEqualZero = (rangefloor.text==0)&&(rangeceiling.text ==0)
<!--- THE FORM IS SET UP TO VALIDATE ON NUMBERS,
SO NO NEED TO VALIDATE WITH JS HERE --->
<!--- ATLEAST A VALUE HAD TO BE GREATER THAT ZERO --->
if (blnEqualZero)
{
alert('Enter a value in the Range or Celing form!', 'Alert', mx.controls.Alert.OK);
}
if (blnGreaterZero)
{
alert('You can only enter one value in either the Range or Ceiling form', 'Alert', mx.controls.Alert.OK);
}
if (varExpressedAs==1)
{
if ((rangefloor.text > 1)||(rangeceiling.text>1))
{
alert('The values entered has to be greater or eqaul to 1', 'Alert', mx.controls.Alert.OK);
}
}

if (varExpressedAs >1)
{
if ((rangefloor.text < 0)||(rangeceiling.text < 0))
{
alert('The values entered has to be percentages are not allowed', 'Alert', mx.controls.Alert.OK);
}
}
</cfsavecontent>