Function if inArray, display text, else display other text....not working
Hello there!
I have this html containing an input with name "product_id":
- <form method="post" class="form-horizontal" onsubmit="return check_add_to_cart(this, false) " enctype="multipart/form-data" id="productDetailsAddToCartForm">
- <input type="hidden" name="action" value="add">
- <input type="hidden" name="product_id" value="167">
- <input type="hidden" name="variation_id" class="CartVariationId" value="">
- <div class="ProductDetailsGrid ProductAddToCart" id="ProductDetailsAddToCart">
- bunch of other irrelevant code....
- </div>
- </form>
What I need to do is display "No Local Delivery" in span #shippingDetails if the value of input with name=product_id is in an array of numbers. Otherwise, if the number is not in the array, it should display "Local Delivery Available".
I have this:
- var noLocal = ["167, 155"];
if ($.inArray($("[name='product_id']").val(), noLocal) >=0) {
$('#shippingDetails').text("No Local Delivery");
} else {
$("#shippingDetails").text("Local Delivery Available");
}
Something isn't right obviously because it doesn't seem to be getting the value of name='product_id'. It just displays "Local Delivery Available" all the time, no matter what the value is.
Thank you in advance!!
Susan