SL8R.co.uk - Code Zone

Code, Code and Code

SL8R.co.uk - Code Zone header image 4

Entries from May 2008

Javascript: Set Focus of HTML Textbox

May 23rd, 2008 · 1 Comment

To set the focus of a HTML text box include this short piece of code in the <head> section
<script>function setfoc() { document.f1.KeyWords.focus(); }
In the example above f1 is the name of the form and KeyWords is the name of the input textbox
In the body section:
<form name=”f1″ action=”youraction” method=”POST”>
<input type=”text” name=”KeyWords” size=”40″ value=”default text”>
</form>
<script language=”JavaScript”>setfoc();</script>

[...]

[Read more →]

Tags: Code

PHP: Checking a DNS entry

May 22nd, 2008 · 1 Comment

It is often useful to check that a given domain name or host is valid, this can be achieved using the checkdnserr() command, as in the following example:
$hostname = “www.domain.com.”;
$dnstype = “MX”;
$bValid = checkdnserr($hostname,$dnstype);
If using a DNS name then ensure the domain ends with the root domain qualifier (the “.”)
If the $dnstype is omitted or [...]

[Read more →]

Tags: Tip

Java: Mix up items in array

May 20th, 2008 · 2 Comments

Quick routine to mix up the items in an array
public Object[] MixUpArray(Object inarray[])
{
  // get the size of the array
  int iSize = inarray.length;
  // create an array the same size as the input array
  Object outarray[] = new Object[iSize];
  // Convert the array to a Vector
  Vector<Object> temparray = new Vector<Object>();
  // Copy the [...]

[Read more →]

Tags: Code

J2ME: Bounds checking of a List

May 8th, 2008 · No Comments

This short routine shows how to ensure a selected item in a list is within bounds. If the list is empty the getSelectedIndex will return -1. The index starts at zero whilst size() will start at 1.
// perform bounds checking
int iIndex = myList.getSelectedIndex();
int iCount = myList.size();
// debugging information
System.out.println(”Index: ” + iIndex + ” Size: ” [...]

[Read more →]

Tags: Code