Remove or Hide SharePoint List’s Menu Options

The following jQuery based JavaScript function can be used to remove the “Edit in Datasheet” option from a SharePoint list. Add a Content Editor Web Part to the list’s standard view and include the following script in the source. The menu option is removed when the page is loaded. The function can be modified or expanded to remove any option using the menu option’s displayed text.

The jQuery library will need to be loaded in order for the function to work properly:

<script src="http://code.jquery.com/jquery-latest.min.js"></script>

The function to remove the “Edit in Datasheet” menu option:

<script language='javascript'>
$(document).ready(function() { 
   $("[text='Edit in Datasheet']").remove();
});
</script>

Automatically E-mail MySQL Database Backup

If you are in a hosting environment where you are responsible for your own database backups, this is a convenient way to have the server generate a backup file of all of your MySQL databases, compress the file, and e-mail it to the specified address. I’ve added this to the local crontab so that it runs on a regular schedule. In order for it to work, you should have a MySQL user account created with the appropriate privileges in order to access your database.

In the crontab, create an entry, as follows, with your customization for both the path to your configuration file and the e-mail address receiving the backup.

mysqldump --defaults-extra-file="/path/to/config/file/.mysqldump.cnf"
          --all-databases
          -ce
  | gzip
  | uuencode dbbackup.gz
  | /usr/sbin/sendmail my_e-mail_address

In the .mysqldump.cnf file, provide the username and associated password that can access the database. Secure .mysqldump.cnf by setting the file permissions 0600 since that file contains your database password in plaintext.

[client]
user=my_database_username
password=my_database_user_password

Select a Drop-down List Item Using JavaScript

The following JavaScript functions are useful for selecting items in HTML drop-down lists. As an example, these can be used if you have server-side code returning values that should then be visually selected on the user’s screen without rebuilding the entire page.

<select id="country_list" name="country_list">
  <option value="1">USA</option>
  <option value="2">Canada</option>
  <option value="3">Mexico</option>
</select>

This first function selects an item based on its value. Pass an object referring to a list element, e.g., document.getElementById(“country_list”), and the value that should be selected.

function selectItemValue(list, selectedValue) {
  for(j = 0; j < list.options.length; j++) {
    if(toUpper(list.options[j].value) == toUpper(selectedValue)) {
      list.selectedIndex = j;
      break ;
    }
  }
}

This second function will select an item based on its displayed text name. Pass in an object referring to a list element, e.g., document.getElementById(“country_list”), and the displayed text value that should be selected.

function selectItemText(list, selectedText) {
  for(j = 0; j < list.options.length; j++) {
    if(toUpper(list.options[j].text) == toUpper(selectedText)) {
      list.selectedIndex = j;
      break ;
    }
  }
}

The following is an example of how to call both functions using the example list:

selectItemValue(document.getElementById("country_list"), 1);
selectItemText(document.getElementById("country_list"), "USA");