Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

Script to allow entry in checbox equal or less than value in recordset

Within a repeat region user will enter the amount of money received, but it can only be as high as the 'balance' remaining.

If user enters a higher value it should not let him/her.

The value is:  PaymentLines.Fields.Item("Balance")

The text box where user enters the amount being received is:  

<input name="amount" type="text" class="bodytext" id="item<%=(PaymentLines.Fields.Item("Id").Value)%>" value="0" size="5" maxlength="10" disabled="true">

I have googled buts seems this is kind of a specific thing and could not find something this particular.

I am using classic ASP/VBscript on this page
SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

I tried the above and I am using IE 11 but it allowed me to enter 120 when the balance is 110 and submitted no problem
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

I did, nothing happened. Remember this is inside a repeat region :$
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Same behavior with the last post of Gary ... no luck, the form still posts
Post your rendered HTML
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Well .. browser is not cutting it. Can we try javascript to accomplish this ?
see my first post in this thread, it's a JS based solution
Avatar of Aleks

ASKER

Ok. Ill try that and let you know how it works
sounds good. I'm stepping out for a bit for lunch and will check in when I get back
Avatar of Aleks

ASKER

Sure
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

The code from Gary works great. Can we also modify the script so that it doesn't allow zero ?  (It may be a negative value because of a reimbursement).
The default is zero so I want to force them to enter a value.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

It didn't work.  It allowed me to enter zero without a warning.

Also I entered a number over the max and I got the alert but it still went ahead and submitted the form
Avatar of Aleks

ASKER

In fact also the first one shows the alert but submits the form anyways.
my code pretty much did work, I just needed to force the values to a numeric type by changing the if statement to

if (parseFloat(balance) < parseFloat(amt))
Avatar of Aleks

ASKER

Actually the first entry worked without the zero validation, sorry about that one
Avatar of Aleks

ASKER

Ah .. I realized what happens. If I click on the button then it validates just fine (First option without the zero validation).
If I hit 'enter' then the alert comes up but the form is submitted.

???
Avatar of Aleks

ASKER

Can we add the validation when the form is submitted instead of when the button is clicked to prevent this from happening ?

this is the form code:

<form action="SPSavePaymentLines.asp?caseid=<%=(Casesjoin.Fields.Item("Id").Value)%>" method="post" name="form1" id="form1"  >
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

There is just one issue with the javascript. Some of the fields are disabled and the default is '0' so it highlights them, it should only check on 'enabled' fields.

I tried leaving the field empty but validation will check and show red box.
It shouldn't validate if the field is disabled
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Thanks to both
Not sure why you are accepting comments that are wrong.