Last active
April 29, 2019 14:26
-
-
Save be-mohand/9e8982a89fa0b601fe410c8420492607 to your computer and use it in GitHub Desktop.
Checking in javascript (with jQuery) that the entered price is equal or greater than the minimum listing price.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Always check that jQuery is available before executing the script | |
$(document).ready(function() { | |
// Execute only if the listing form exists in the page | |
if($('#listingForm').length > 0) { | |
var checkMinimumListingPrice = function() { | |
// Check if the price is equal or greater than 1 | |
if($('#ListingPrice').val() < 1) { | |
alert('Price should be equal or greater than 1'); | |
return false; | |
} | |
return true; | |
}; | |
// Check when form is submitted | |
$(document).on('submit', '#listingForm', function() { | |
if(!checkMinimumListingPrice()) { | |
return false; | |
} | |
}); | |
// Check when the price field is filled | |
$('#listingForm').on('focusout', '#ListingPrice', function() { | |
if(!checkMinimumListingPrice()) { | |
return false; | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment