Articles tagged with: Code
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...]
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...]
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...]
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...]
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...]
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...]
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);
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).


