Skip to content

Instantly share code, notes, and snippets.

@hilukasz
Created May 9, 2012 19:40
Show Gist options
  • Save hilukasz/2648271 to your computer and use it in GitHub Desktop.
Save hilukasz/2648271 to your computer and use it in GitHub Desktop.
var newSalesPageInputs = [var $newSaleAddress = $('#newSaleAddress'),
var $newSaleTitle = $('#newSaleTitle'),
var $newSaleDescription = $('#newSaleDescription'),
var $newSaleSummary = $('#newSaleSummary'),
var $newSaleItems = $('#newSaleItems')];
for(var i = 0; i < newSalesPageInputs.length; i++) {
alert(i);
$newSalesPageInputs[i].focus(function () {
$newSalesPageInputs[i].attr('data-value', $newSalesPageInputs[i].val());
$newSalesPageInputs[i].val('');
});
$newSalesPageInputs[i].blur(function () {
if ($newSalesPageInputs[i].val().length === 0) {
$newSalesPageInputs[i].val($newSalesPageInputs[i].attr('data-value'));
}
});
}
// this is based on this code:
// don't want to do this for EVERY variable, but I guess I could set a class instead of an ID?
$searchAddress.focus(function () {
$searchAddress.attr('data-value', $searchAddress.val());
$searchAddress.val('');
});
$searchAddress.blur(function () {
if ($searchAddress.val().length === 0) {
$searchAddress.val($searchAddress.attr('data-value'));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment