Tag Archive: javascript

Bash MySQL function

I use this function to run SQL queries from bash scripts.

fRunQuery(){
# This function should always be preceeded by a SQL statement
# Loaded into the variable SQL
# ie) SQL="SELECT * FROM table"; fRunQuery
# The results of the query will be loaded into the variable
# $RESULT:
RESULT=`mysql --skip-column-names -h${dbhost} $db -u${dbuser} -e"${SQL}" -p${dbpass}`
return 0
}

Permanent link to this article: http://www.lukemacneil.com/2010/04/26/bash-mysql-function/

Javascript to format date like mm/dd/yyyy hh:mm:ss


var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;//January is 0!
var yyyy = today.getFullYear();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
if(dd<10){dd='0'+dd}
if(mm<10){mm='0'+mm}
d=mm+'/'+dd+'/'+yyyy+' '+hours+':'+minutes+':'+seconds

Permanent link to this article: http://www.lukemacneil.com/2010/04/26/javascript-to-format-date-like-mmddyyyy-hhmmss/

AJAX waiting indicator

The following code snippet will display a waiting indicator during any AJAX request.

//Adds a wait indicator to any ajax requests
$('body').ajaxStart(function() {
$('#loading').show();
});
$('body').ajaxStop(function() {
$('#loading').hide();
});

Permanent link to this article: http://www.lukemacneil.com/2010/04/26/ajax-waiting-indicator/

Just another IE6 layout hack.

These just seem to add up.

<!--[if IE 6]>
<style type='text/css'>
div{zoom:1}
</style>
<![endif]-->

Permanent link to this article: http://www.lukemacneil.com/2010/04/26/just-another-ie6-layout-hack/

Use jQuery to highlight input boxes on focus.

// Make focused fields stand out.
$('input[type="text"]').addClass("idleField");
$('input[type="text"]').focus(function() {
$(this).removeClass("idleField").addClass("focusField");
if (this.value == this.defaultValue){
this.value = '';
}
if(this.value != this.defaultValue){
this.select();
}
});
$('input[type="text"]').blur(function() {
$(this).removeClass("focusField").addClass("idleField");
if ($.trim(this.value == '')){
this.value = (this.defaultValue ? this.defaultValue : '');
}

Permanent link to this article: http://www.lukemacneil.com/2010/04/23/use-jquery-to-highlight-input-boxes-on-focus/

Older posts «