Daily Technology News, Tips, and Reviews | Subscribe to Jason Slater Technology BlogTechnology Feed | Join Jason Slater on TwitterTwitter | Thursday 2nd September 2010

Articles tagged with: Code

Javascript: CSS rollover List routine
Wednesday, 18 June 2008
Javascript: CSS rollover List routine

To quickly loop through a list node and set a rollover CSS value, use the following // Set all LI of a node to rollover CSS // Use two CSS class, e.g. item and itemover function updateList(String nodename) { if (document.all&&document.getElementById) { navRoot = document.getElementById(nodename); for (i=0; i<navRoot.childNodes.length; i++) { node = navRoot.childNodes[i]; if (node.nodeName==”LI”) [read more...]

PHP: Add Slashes to text
Tuesday, 3 June 2008
PHP: Add Slashes to text

It is sometimes necessary to maintain the special characters in text, such as the apostrophe, speech marks, null character and backslash as these can be mis-interpreted by systems such as SQL if not modified appropriately. The generally accepted method of achieving this is to use the addslashes command which prefixes the special characters with the [read more...]

Javascript: Set Focus of HTML Textbox
Friday, 23 May 2008
Javascript: Set Focus of HTML Textbox

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” [read more...]

PHP: Checking a DNS entry
Thursday, 22 May 2008
PHP: Checking a DNS entry

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 [read more...]

Java: Mix up items in array
Tuesday, 20 May 2008
Java: Mix up items in array

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   [read more...]

J2ME: Bounds checking of a List
Thursday, 8 May 2008
J2ME: Bounds checking of a List

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: ” + [read more...]

PHP: Avoiding mySQL Injections
Wednesday, 30 April 2008
PHP: Avoiding mySQL Injections

Sample code to avoid SQL injections using mysql_real_escape_string (http://uk.php.net/mysql_real_escape_string) which converts special characters to escape sequences to ensure they are suitable for submission to SQL $mySQL = “UPDATE address SET postcode=’.mysql_real_escape_string($postcode).’ WHERE id=’.mysql_real_escape_string ($account).’”; $myResult = mysql_query($mySQL);

PHP: Require() and Include()
Wednesday, 23 April 2008
PHP: Require() and Include()

Essentially, require() and include() act in much the same way in that they both include the contents of another file – the only difference being that if include() fails then processing will continue (but produce a warning) but if require() fails then processing will stop with a fatal error (as well as produce the warning).