Archive for the ‘Script snippet’ Category

Text Field Auto-Fill

Thursday, April 1st, 2004

A brief break from the eye-bleeding CSS talk. LOL! ;o)

I needed a text field to be prefilled with text. If the user clicked on it, the text would clear out. If they “left” the text field (changed focus) without changing it - I needed it to revert back to the original text. If they DID enter information in it, I needed it to NOT revert back to the original text. (Clear as mud?)

Here’s what I mean:

Here’s how (and why) I did this:
(more…)

cron jobs

Wednesday, January 14th, 2004

Sometimes the simplest thing are the things that seem the hardest. You’re almost embarrassed when you finally figure it out - and realize how simple it was.

Cron jobs. Did you know you can create a script (that could technically be run if you pulled the page up in a browser) - but lets say you wanted to run this script on a regular basis. You can set up a cron job to run this php script.
(more…)

Radio Button - Changing selection (checked) and focus

Wednesday, January 14th, 2004

Just some snippets for safe keeping regarding radio buttons. One that will change which radio button is selected. The other that will change the focus to the appropriate radio button (useful when validating that fields are filled out in a form)
(more…)

PHP: Stripping out predicted text from a string

Tuesday, December 30th, 2003

(Sort of inline with the previous moblog post) All of Sam’s posts are accompanied by a few lines of text that the phone automatically adds. (There’s probably a setting to remove it, but we can’t find it at the moment). So I used the following script to hide the text using php.
(more…)

Javascript: Pull-down menus with pop-up links

Thursday, December 11th, 2003
  • Original Script: The JavaScript Source
  • Corrections: The original was incorrectly pasted on the source page, so it failed to execute properly. I fixed that problem and also added an option for background and text colors on the pull-down menu. Scrollbars and toolbars were added to the pop-up links.
  • Instructions: Change the bold code to meet your site’s needs.
  • Customizations: Go for it! The menu font size is set at 10pt by default, but I use 9pt on BB. The background color is white and text is black, but delete the options or change to meet your needs.
    (more…)

  • Javascript: Removing new lines (”\n” or “\r”) from text

    Tuesday, December 2nd, 2003

    A line break can be created by either a new line (ie. “\n”) or a carriage return (ie. “\r”). (more info here)

    In my particular use, I had a field that could take several email address that would be seperated by either a comma, semicolon or line break:
    (more…)

    Using PHP to FTP - and import a CSV file into a database

    Friday, November 21st, 2003

    I needed to grab a (CSV) file via FTP and import it into a database. The part that I thought would be the hardest (the FTP part) was actually very simple. Once again, PHP saves the day with incredibly powerful built in functionality. Here is the simple code that will connect to an FTP server and download a file:
    (more…)

    Skinnable Comment Pop Ups

    Wednesday, October 22nd, 2003

    I did not write this code but I have been using it for a while. I have gotten quite a few emails about it and thought I would post it here to share with the masses. It’s been working perfectly on my site for some time. This method can be used to skin your comment and trackback popups as well as any other pages that you link to your site. I also use it to skin my blogroll page.
    (more…)

    Main and secondary categories in MT (with a little help from PHP)

    Saturday, September 20th, 2003

    The point of this script-snippet is so you can set up two hierarchies of categories. So there’s a main category, and a few “sub-categories” below it. An example of this is on Christine’s Pixelog site, on her album page.

    This differs from the way MT has “Primary” and “Secondary” categories in that in mine, the sub-categories for a main category, can only be a sub category of that one main category - not any other main category. Here’s another example: Ohnozone.net . In the sidebar, scroll down to the “categories”, You’ll see there’s a main category “Appearances”, and there’s sub categories beneath it. “Interviews & Articles” and “TV”
    (more…)

    Basic MySQL connection and query with PHP

    Wednesday, September 17th, 2003

    I use this almost on a daily basis, and yet I can’t commit it to memory. So I don’t have to go searching for it each time I need to write it…

    $databaseName = “YOURDATABASENAME“;
    $dbconnection = mysql_connect(”localhost”, “DATABASE-USERNAME“, “DATABASE-PASSWORD“) or
    die (’I can?t connect to the database.’);
    mysql_select_db($databaseName,$dbconnection);
    $value = “SOMEVALUE“;
    $query = sprintf(”SELECT FIELDNAME from TABLENAME where FIELDNAME=’%s’;”, $value);
    $result = mysql_query($query);
    $totalNum = mysql_num_rows($result);
    while ($row = mysql_fetch_array($result)) {
    echo $row['FIELDNAME'];
    }
    ////////OR//////
    for ($i =0; $i < $totalNum; $i++) {
    $row = mysql_fetch_array($result);
    echo $row['FIELDNAME'];
    }