linnium
05-15-2003, 12:33 PM
I'm using a form validator to make sure the user is not choosing a minimum number that is greater than the maximum number in their search criteria. Here is a sample of the code:
<head>
<script>
function chkSubmit()
{
if (document.formname.minprice.value > document.formname.maxprice.value)
{
alert('The minimum price cannot be greater than the maximum price.');
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form name="formname" action="action.url" method="post" onSubmit="return chkSubmit(this)">
This seemed to work fine, but during testing, when I chose 850,000 as the min and 1,000,000 as the max, submitting triggered the alert and a return of false. I think I understand why this is happening, but I don't know how to do a correct comparison without doing a length count and then adding zero's to the front of the shortes value. Please help.
Thank you.
<head>
<script>
function chkSubmit()
{
if (document.formname.minprice.value > document.formname.maxprice.value)
{
alert('The minimum price cannot be greater than the maximum price.');
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form name="formname" action="action.url" method="post" onSubmit="return chkSubmit(this)">
This seemed to work fine, but during testing, when I chose 850,000 as the min and 1,000,000 as the max, submitting triggered the alert and a return of false. I think I understand why this is happening, but I don't know how to do a correct comparison without doing a length count and then adding zero's to the front of the shortes value. Please help.
Thank you.