Click to See Complete Forum and Search --> : Simple validation problem


aro72
06-06-2005, 01:24 PM
I have following function to validate couple of things:
1. Make sure that data has been changed (validation works)
2. Make sure that data entered to txtRAmount is numeric (validation works)
3. Make sure that number entered to txtRAmount in not larger than number in txtTAmount (doesn’t work)

I’m new to Javascripting, please help

function FormValidate()
{
if (!blnDataChanged)
{
self.alert("Please make a change before submitting information.");
return false;
}

var d = document.forms[0];


if (!ValidateNumeric(d.txtRAmount, "Please enter a valid amount")) return false;
return true;

if(d.txtRAmount.value >= d.txtTAmount.value) {
alert("R amount cannot be larger than t amount.")
return false;}
}

phpnovice
06-06-2005, 06:39 PM
if(Number(d.txtRAmount.value) >= Number(d.txtTAmount.value)) {
alert("R amount cannot be larger than t amount.")
return false;}

aro72
06-07-2005, 09:04 AM
Thanks phpnovice,

It is not working. Please let me know if you have suggestions.

Kor
06-07-2005, 10:08 AM
It is not working.

It is not working what? The return false is not working? This case make sure that your function is called onsubmit in the form element, like that:

<form onsubmit="return FormValidate()">

and remove the green colored

if (!ValidateNumeric(d.txtRAmount, "Please enter a valid amount")) return false;
return true;

aro72
06-07-2005, 10:44 AM
This staitment is not working:

if(Number(d.txtRAmount.value) >= Number(d.txtTAmount.value)) {
alert("R amount cannot be larger than t amount.")
return false;}

Kor
06-07-2005, 10:47 AM
This staitment is not working:

What is not working? The alert? The return false?

It should work. Can we see your code (or a link to it)? Must be another error somewhere.

phpnovice
06-07-2005, 11:08 AM
This staitment is not working:

if(Number(d.txtRAmount.value) >= Number(d.txtTAmount.value)) {
alert("R amount cannot be larger than t amount.")
return false;}
It will work if you remove the return true that you show before that statement.

function FormValidate()
{
if (!blnDataChanged)
{
self.alert("Please make a change before submitting information.");
return false;
}

var d = document.forms[0];

if (!ValidateNumeric(d.txtTAmount, "Please enter a valid amount")) return false;
if (!ValidateNumeric(d.txtRAmount, "Please enter a valid amount")) return false;

if(Number(d.txtRAmount.value) >= Number(d.txtTAmount.value))
{
alert("R amount cannot be larger than t amount.")
return false;
}

return true;
}

aro72
06-07-2005, 11:15 AM
Here is the code that calls this function:
<form name="frmR" method="post" action="REdit.asp" onSubmit="return FormValidate();">

Here is the entire function:

function FormValidate()
{
if (!blnDataChanged)
{
self.alert("Please make a change before submitting information.");
return false;
}

var d = document.forms[0];


if (!ValidateNumeric(d.txtRAmount, "Please enter a valid amount")) return false;
return true;

if(Number(d.txtRAmount.value) >= Number(d.txtTAmount.value)) {
alert("R amount cannot be larger than t amount.")
return false;}
}

The last if statement should not allow to input larger number to txtRAmount than it is in txtTAmount. I know that function is getting called because it validates other 2 ‘if’s but it totally ignores the last if. I’m not getting an alert and return false is also not working.

aro72
06-07-2005, 11:18 AM
Thanks a lot, it worked.

phpnovice
06-07-2005, 11:30 AM
Cheers.