jQuery Any

by Kyle Mitofsky

HTML

<input type="text" value="">
<input type="text" value="hi">
<input type="text" value="">











<div style='position:fixed;bottom:0;left:0; background:lightgray;width:100%;'>
    About this SO question:
    <a href='http://stackoverflow.com/q/10413716/1366033'>
        Jquery check form to see if any inputs has value
    </a>
</div>

JavaScript

jQuery.fn.any = function(filter){ 
	for (i=0 ; i<this.length ; i++) {
  	 if (filter.call(this[i])) return true;
  }
  return false;
};

$(function() {
	
  var gotMatch = $(":input").any(function() { 
    return this.value == 'hi';
  });

  if (gotMatch) {
    console.log("Hello to you too!");
  } else {
  	console.log("Why don't you say Hi!");
  }
  
})