I had been using an autocomplete plugin by bassistance. 2 months later jQuery UI added autocomplete to their list of widgets. Like many plugins out there I was unable to find an autocomplete that was easy to use for my purposes. The closest I recently came to was the sexy combo plugin. I cant remember why but it was just a tad short of what I wanted to do, and I’m still quite a javascript novice.
I came up with a way to use the jQuery UI autocomplete widget as a <select> that you could also type in something if the choices in the dropdown didn’t fit your needs.

This example uses a local data source, but you can come up with creative ways to use remote JSON sources if you like.
<script type="text/javascript">
$(document).ready(function() {
// dropdown/ auto suggest
$(".ui_dropdown").autocomplete({
minLength: 0,
delay: 0
});
$(".ui_dropdown").click(function(){
var input = $(this);
var inputID = input.attr('id');
// close if already visible
if (input.autocomplete("widget").is(":visible")) {
input.autocomplete("close");
return false;
}
// set source(s)
var myData = '';
if(inputID == 'input1'){
myData = ["foo","bar","hello","world"];
} else {
myData = ["1","2","3","4"];
}
// load source
input.autocomplete({
source: myData
});
// fire search event
input.autocomplete("search", "");
input.focus();
return false;
});
});
</script>
In this script I am using the input id’s to define the data source.
I’m rather new to both javascript and jQuery. I ran into an issue while cloning table rows that had inputs, and jQuery UI datepicker.
The cloned datepicker input would insert the picked date into the original inputs rather than the cloned row.

The inputs in my table rows had no ID’s. So what I found was either jQuery or UI was dynamically creating it’s own DOM id’s for the inputs in the table rows that had the datepicker call. Datepicker also was dynamically inserting a class “hasDatepicker” into the inputs that had the datepicker call.
I resolved this by:
1. Looping through the cloned rows inputs looking for any inputs with the class “hasDatepicker”.
2. Removing the hasDatepicker class from any inputs with that class.
3. Getting that inputs current id, incrementing it by 1, and reassigning it.
4. Re-initializing the datepicker call.
<script type="text/javascript">
$(document).ready(function(){
// -- Clone table rows
$(".cloneTableRows").live('click', function(){
// do the cloning...
// new rows datepicker need to be re-initialized
$(newRow).find("input").each(function(){
// if the current input has the hasDatpicker class
if($(this).hasClass("hasDatepicker")){
var this_id = $(this).attr("id"); // current inputs id
var new_id = this_id +1; // a new id
$(this).attr("id", new_id); // change to new id
$(this).removeClass('hasDatepicker'); // remove hasDatepicker class
$(this).datepicker(); // re-init datepicker
}
});
});
});
</script>
Whats really neat about this particular js, is that you can call it from any table that has an id.
The only thing I have yet to figure out is how to reset the cloned datepicker to use the default class called date format.
So in addition to reformatting friends and relatives computers, about every 2 years I clean out my own. Each time I have, I’ve lost my Notepad++ FTP synchronize settings.
In Vista they can be found in:
C:\Users\AppData\Roaming\Notepad++\plugins\config\FTP_synchronize.ini

Copy them to backup and replace. In case an update gets hosed, or you are re-installing.
I found myself working with text files a little more recently and was looking for a way to tell if a directory was empty. Why? In my case I wanted to check if a directory was empty. If it wasn’t, to grab the data in those files and put them in a database.
What I didn’t want to do was have the expense of connecting to a database if the directory didn’t have any files in it to begin with. After chatting with my good friend TDavid at php-scripts.com, I decide to run with his suggestion…
Fill (or don’t fill) a variable with information if there were files in the directory. Then test the var to confirm or deny if there are files in the directory. It’s really a small bit of code…
//----- Check if ticket dir has files. If it has files,
// set a variable to hold the list of file names.
$dir = "../path/to/my/textfiles"; // set directory
if($handle = opendir($dir)){ // open directory
while(($file = readdir($handle)) !== false){
if($file != "." && $file != ".."){
$file_list[] = $file; // Set file list variable
}
}
closedir($handle); // Close directory
}
If there are files in this directory, the variable $file_list would not only exist, but also contain files. For example…
Array
(
[0] => 195972.txt
[1] => 196027.txt
[2] => 196053.txt
[3] => 196067.txt...
)
If there aren’t any files in this directory, the variable $file_list would not even exist because no $file would be inserted into it. At this point we can check/ test the variable to output or do further processing…
if(isset($file_list)){
echo "This dir has files!";
// perform further processing
// eg: collect each files contents
} else {
echo "This dir has NO files!";
// stop processing
// Not much do do with this since there are no files
}
Of course there are a few ways of checking to see if a directory is empty, but this way seemed to be the most simplistic to me. If you wanted to you could turn the entire lot into a function for reuse, and less script code clutter.
Comments? Questions?
php, empty directory
I came across a situation where I needed to pull records from 1 db to another on a recurring basis. I read many different ways to do it via searching around the net. Some of the suggestions included creating a temporary table and copying it over. What was lacking was that sometimes the new table also needed to be UPDATED, as the information changed from the original table.
I’ve come up with a dirty little example to show this can be done. There are more keywords that can enhance the ON DUPLICATE KEY UPDATE function even more. The Example is assuming an “employees” table that looks like so:
| employees |
| id (PK) |
| first_name |
For brevity, I’ve left out connection data etc;
$myArray = array(0 => array('id' => '1', 'fname' => 'Steve'),
array('id' => '2', 'fname' => 'sara'),
array('id' => '3', 'fname' => 'Matt')
);
// Don't forget to validate & clean your data
// Connect to db here
foreach($myArray as $key => $value){
$query = "INSERT INTO employees
(id, first_name) VALUES ('$value[id]', '$value[fname]')
ON DUPLICATE KEY UPDATE first_name = '$value[fname]'";
$result = mysql_query($query);
if(!$result){
print("Problem: " . mysql_error() . "");
} else {
print("Success !");
}
}
Read the manual on this for more information. This snippet will INSERT if a UNIQUE (in this case ‘id’) does not exist. It will UPDATE any existing unique. In this case any existing ‘id’s, the ‘first_name’ column will get updated.
One could also use the REPLACE function. As I understand the difference, REPLACE will DELETE any matching uniques, and INSERT a new record in it’s place.
Comments? Better ways? I’m always up for learning something new so please chime in ;-)