I am trying to write a script that checks if any of the input fields has no value, and when it does it needs to display an alert message and return false.
The input field below is just a small example of my real world application. There maybe more then 5 input fields with a value already in it, and 1 or more input fields that have no value in it
The input fields that has no value are only the ones with returned data(html code) from a ajax post
The problem is that the script is not displaying an alert message when one of the input fields has no value. (The one with the ajax returned data)
Any help would be really appreciated.
Below is the code that I am using.
HTML CODE
<input type='text' class='option_category' name='option_category_config[35196][option_cat_name]' value='Size of Neapolitan' >
<input type='text' class='option_category' name='option_category_config[35197][option_cat_name]' value='Choice of Whole Pizza Toppings' >
//Empty input field. This is not even shown on the HTML source code. I needed to copy and paste it from firebug. I am not sure if that is the reason it doesn't return false
<input class="option_category" type="text" placeholder="Enter category name" value="" name="option_category_config[35236][option_cat_name]">
jquery code
var option_cat = $('.option_category[name*="option_category_config"]');
$('input[name="update_menu_options"]').on('click', function(){
option_cat.each(function(){
var check_val = $(this).val();
console.log(check_val);
if(!check_val){
alert('there are missing input(s)');
return false;
}
});
return false;
});