This is my HTML code:
<?php
$filename = 'codes.txt';
$data = file($filename);
foreach($data as $key => $val){
$array[] = $val;
}
?>
<form id="checkinput" action="#">
<input class="zipcodes" name="zipcodes" value="" type="text">
<input class="zip-sub" type="button" value="Continue" id="submit">
</form>
Thi is jQuery code:
jQuery(document).ready(function() {
jQuery('.zip-sub').click(function() {
var zip = jQuery('.zipcodes').val();
var zipcodelist = <?php echo json_encode($array); ?>;
if( jQuery.inArray(zip, zipcodelist) != -1){
alert('value is .txt file !');
} else {
alert('value is not .txt file');
}
});
});
This is type of some variable in .txt file:
12345
23456
56789
What i need: when i fill data in input field i can check its in variable in .txt file or not
Its working with last variable in array, not at all. I dont know where's the code is wrong ? Pls help. Thanks in advance !