I have a function that sets text input’s to “” whenever they are clicked/focused on. It works fine when I hard code defaults values into an array, however I’d like to not do this and instead get a collection of the default values so I can use it across several pages without having to add values to manually add values to the array.
I’m trying to loop through all of the input’s, and create an array but my newb skills are preventing me from doing so, here is what I have so far:
$(function() {
var defaultValues = $('input[type="text"]').each(function) {
$(this).val();
)}; // instead of simply ["default value 1", "default value 2"]
$('input[type="text"]').live("focus", function() {
$(this).css("color", "#000000");
if (jQuery.inArray($(this).val(), defaultValues)) {
$(this).val("");
}
});
});
Try
.mapinstead:…and clean up your syntax 😐
Demo: http://jsfiddle.net/Ew7h8/