Log In

Email:
Password:
Keep me logged in

Forgot Password

Email:




Archives
2013
March (7)
February (13)
January (14)
2012
December (12)
November (12)
October (12)
September (6)
August (12)
July (6)
June (12)
May (6)
April (12)
March (6)
February (12)
January (12)
2011
December (11)
November (14)
October (11)
September (4)
August (16)
July (8)
Categories
CSS (28)
jQuery (116)
PHP (52)
.htaccess (5)
iPod (1)
iPhone (16)
Sponsored Links


In Array
jQuery Javascript
Browse Category | Tuesday, August 23, 2011 |

Description: Need to test if a value is in an array? Here's a Javascript alternative. No need for an extra jQuery plug-in, however jQuery is a shortcut for labeling the elements.







Code:
<script src="http://wcetdesigns.com/assets/javascript/jquery.js"></script>
<script>
$(function(){
var a = new Array ("one", "two", "three", "four");

$("#a").keyup(function(k){
var v = $("#a").val();
if(v){
$("#b").html("Not in here!!!");
for(i=0; i<a.length; i++){
if(v==a[i]){
$("#b").html("Okay!!!");
}
$("#b").html("");
}
});
});
</script>
<input id="a"><span id="b"></span><br>
Test with "<b>one</b>", "<b>two</b>", "<b>three</b>", or "<b>four</b>" <span style="color: red">(Use one only, no spaces!)</span>
 0    0
Views: 885 Downloads: 2




(Optional in case you want a reply)



0 Comments