Skip to content

Instantly share code, notes, and snippets.

@be-mohand
Last active April 29, 2019 14:26
Show Gist options
  • Save be-mohand/9e8982a89fa0b601fe410c8420492607 to your computer and use it in GitHub Desktop.
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.
// 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