Take the tour ×  I am creating a site that requires a very small
postcode checker. I have approx 8 postcode prefix's, HX, HD, BD,
LS etc in an array. I also have a simple input field and submit
btn. When the user types in a postcode for example HX5 9DU I
want Jquery to check the array, if there is match for the first
2/3 letters I want a div to fade in displaying a message.  How
would I do this? Many thanks in advance.  share|improve this
question add comment  2 Answers  up vote 1 down vote accepted
Here's one way to do it:    <div id="message">some message</div>
<input type="text" id="myInput" />​   $(function() {  // Wrap
the code such that it will run after document loads
$("#message").hide();   // First hide the message      var
prefix = ['HX', 'HD', 'BD', 'LS'];   // Create your array of
prefixes      $('#myInput').keyup(function(e) {   // Trigger an
event handler on each 'keyup'          var value =
$(this).val();   // Grab the current value of the input
// Store first two characters