The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
2 number fields, dont submit form if 2nd is bigger than 1st (validation)
Discuss 2 number fields, dont submit form if 2nd is bigger than 1st (validation) in the JavaScript Development forum on Dev Shed. 2 number fields, dont submit form if 2nd is bigger than 1st (validation) JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 8th, 2010, 03:12 PM
|
|
Registered User
|
|
Join Date: Feb 2010
Posts: 18
Time spent in forums: 4 h 27 m 16 sec
Reputation Power: 0
|
|
|
2 number fields, dont submit form if 2nd is bigger than 1st (validation)
I have 2 fields for the user to fill in (as part of a larger form)...
Code:
<input name="total_items" type="text" class="required digits" maxlength="3" id="total_items" autocomplete="off" />
<input name="avail_items" type="text" class="required digits" maxlength="3" id="avail_items" autocomplete="off" />
i need to submit the form, but ONLY when the second value is smaller than or equal to the first value.
how can I do this? I have been trying to modify equalto from the jquery validation but no success. where do i start?
help
|

March 9th, 2010, 02:49 AM
|
 |
hack of all trades
|
|
Join Date: Jan 2009
Location: Madrid
|
|
|
how are you submitting at the moment ? with jq formajax plugin? with a standard submit button? with a custom ajax function? are you using validation for any other part? if so is it standard js? jq validate plugin?
and is there a chance the values will be decimals? or are they only whole numbers?
__________________
a: true is 1 and false is 0 right?
b: 1
|

March 9th, 2010, 01:01 PM
|
|
Registered User
|
|
Join Date: Feb 2010
Posts: 18
Time spent in forums: 4 h 27 m 16 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by haydenchambers how are you submitting at the moment ? with jq formajax plugin? with a standard submit button? with a custom ajax function? are you using validation for any other part? if so is it standard js? jq validate plugin?
and is there a chance the values will be decimals? or are they only whole numbers? |
standard submit button, its just a form that posts the value to a php page which deals with it (add to mysql db and return to another page)
there is validation on it using jquery validation maxlength='3', 'required', and 'digits'... and a warn message shows next to the field and prevents submission if those conditions are not met
whole numbers only.
|

March 9th, 2010, 01:18 PM
|
|
|
|
What Hayden is asking, I think, is what have you tried so far? You are asking for help with some Javascript, so what Javascript have you used/written?
Last edited by Winters : March 9th, 2010 at 01:30 PM.
Reason: typo
|

March 9th, 2010, 04:11 PM
|
|
Registered User
|
|
Join Date: Feb 2010
Posts: 18
Time spent in forums: 4 h 27 m 16 sec
Reputation Power: 0
|
|
i tried to modify jquery validate...
Code:
$(document).ready(function(){
$("#addServiceForm").validate({
rules: {
avail: {
compareTo: "#total"}}});});
PHP Code:
// http://docs.jquery.com/Plugins/Validation/Methods/equalTo
compareTo: function(value, element, param) {
return value >= $(param).val();
},
|

March 9th, 2010, 04:54 PM
|
 |
hack of all trades
|
|
Join Date: Jan 2009
Location: Madrid
|
|
|
that’s exactly where I would have gone (but basing it on the max function) .. not sure why its not working..
have you tried passing in the val straight to the max function ?
avail: {
max: $("#total").val()
|

March 9th, 2010, 05:26 PM
|
|
Registered User
|
|
Join Date: Feb 2010
Posts: 18
Time spent in forums: 4 h 27 m 16 sec
Reputation Power: 0
|
|
Code:
$(document).ready(function(){
$("#addServiceForm").validate({
rules: {
avail: {
max: $("#total").val()}}});});
didn't work  it just says "Enter a value less than or equal to " which I assume means it cant see the value in the other box
i.e. Enter a value less than or equal to {0}
even when i enter the value in 'total' before 'avail', it still cant find the value
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|