Reputation: 1320
I have the following jQuery that performs come validation on POST
(function($) {
$( document ).ready(function() {
jQuery('#post').submit(function() {
if ($("#_sku").val() == '') {
alert("Please enter a valid GTIN");
$('#ajax-loading').hide();
$('#publish').removeClass('button-primary-disabled');
$('#_sku').focus();
return false;
}
return true;
});
});
}(jQuery));
This currently works well, however I need to add another condition to the if statement
. I need to apply the rule only when the value of the following select box is eqaul to "simple"
<select id="product-type" name="product-type">
<optgroup label="Product Type">
<option value="simple" selected='selected'>Simple product</option>
<option value="grouped" >Grouped product</option>
</optgroup>
</select>
I have tried this in my if statement:
if ($("#_sku").val() == '' && $("#_product-type").val() == 'simple') {
But this does not apply the rules within the if statement when product-type is equal to "simple". Could anyone suggest what the issue is here?
Upvotes: 0
Views: 5942
Reputation: 2648
This should work for you. You can also use === instead of == which is more faster and accurate. Because === doesn't make any cast
if ($("#_sku").val() == '' && $("#product-type").val() == 'simple')
Upvotes: 3