Friday, December 19, 2003

Dave's Quick Search Taskbar Toolbar Deskbar

Dave's Quick Search Taskbar Toolbar Deskbar. This tool is a toolbar for your desktop. It allows you to search many search engines. You can search for many things including dictionary definitions, stock quotes, newsgroups, weather, translated text/webpages, open websites and many more. You can add functionality to it through HTML configuration files. It is an Open Source project as well.

Wednesday, December 17, 2003

HTML-Kit

HTML-Kit is one of the best HTML editors available and it is completely free. As well as syntax highlighting for various file type (HTML, ASP, PHP, CSS, etc) it also allows you to validate you CSS and HTML with online validators - and check your HTML with HTML-Tidy offline. It is has a wide range of plugins available (you can even develop your own). Check out the extensive feature list. My favourite plugins:

  • hkDivStarter - create layouts using CSS and DIV tags (added 9 Jan 2004)
  • hkTagTreeLite - display (X)HTML / XML as a tree structure, can be used to navigate the code (added 9 Jan 2004)
  • cmBatchFind - find text in multiple files
  • cmBatchDelete - delete multiple files
  • cmBatchReplace - replace text in multiple files (supports regular expressions and can back up changed files)
  • cmCodePublish - formats your code to allow you to publish it as HTML (with syntax highlighting)
  • cmCodeCrusher - strips out superfluous whitespace and comments in your code
  • cmCodeFinder - lists hkScript, PHP, Perl, HTML and Ruby functions/tags in your code, which you can jump to by selecting from the list
  • cmLookupWord - look up selected text in Google Web and Groups, Open Directory Project, Dictionary.com and Dict.org, Thesaurus.com, and Acronymfinder.com.
  • cmTreeView - display HTML/XML document in a 'tree' structure
  • irLinkChecker - check your links (plugin written in PHP)
  • twJavaScript - insert JavaScript snippets
  • gmPageReport - generate a report on a file you choose, very extensive
  • rdFunctionList - list JavaScript, PHP and hkScript functions in a drop down list
  • irShowMatchingParens - show matching brackets in your code
  • irHTMLShow - outline certain HTML elements in preview mode

Thursday, December 11, 2003

StumbleUpon

A very useful toolbar (for Internet Explorer / Mozilla / Netscape) that allows you to find websites that other users recommend. It is community based so you can also recommend sites as well. Download from http://www.stumbleupon.com/

Has two ratings - Not for me and I like it. Use on any sites you like (or dislike). The more sites you rate, the better results you get. Sites are put into interest categories (i.e. Web Developer, Programming) - so if you add your interests, you will get better results. A good way of browsing the web without using a search engine.

Almost 300,000 sites listed and 83,000 members. Going since mid-2002 (site redesign January 2003 - approx 20,000 members). Hopefully the more users and the more websites, the better it will get.

Update - Jan 9 2004: 90,614 members, 309,229 websites - seems to be growing quickly, perhaps 10,000+ members by February

Update - Mar 5 2004: 104,872 members, 407,710 websites. Perhaps there will be 1/2 million sites by late April / early May? More member features have been added (member groups - for those with similar interests)

Tuesday, December 02, 2003

Editing Databases

Couple of free tools for editing databases.
  • Office-QB Standard - free download for accessing databases via ADO and ODBC. Basic querying of data, so knowledege of SQL syntax recommended. Office-QB Pro has more features
  • CuteSQL - free download, connects via ADO and ODBC
  • DbaMgr - two versions available. DbaMgr is for SQL Server 7.0 and MSDE 1.0, DbaMgr2k is for SQL Server 2000 and MSDE 2000
  • SQLExecMS - version 1 is free. Can edit MSDE and SQL Server 7.0/2000 databases
  • WinSQL - Lite version free (requires free registration after 30 days). Connects to any ODBC database
  • MySQL Control Centre - edit MySQL databases
Online editing via ASP:
  • 1ClickDB - free (basic editing of data in tables and export from tables and views) and pro (extra features like stored procedures and import) versions available
  • Universal Table Editor - using VBScript class
Set permissions on the folders that you install these to, else anyone with the URL could edit the data.

Saturday, November 22, 2003

List Cookies

List cookies that have been set for a web site:
// split up cookie into array (;  is deliminator)
thisCookie = document.cookie.split('; ');
// loop through array
if(thisCookie.length > 0){
	// open list
	document.write('<ul>');
	for(i=0;i<thisCookie.length;i++){
		// cookie name
		document.write('<li><strong>Cookie Name:<\/strong> ' + thisCookie[i].split('=')[0]);
		// cookie value
		document.write(', <strong>Value:<\/strong> ' + unescape(thisCookie[i].split('=')[1]) + '<\/li>');
	}
	// close list
	document.write('<\/ul>');
}
Use for seeing what cookies your site has set.

Friday, November 14, 2003

Favelet: Highlight A Tags

A favelet for highlighting anchor tags: Highlight A.

How to use favelets (from Accessify.com). Accessify also have quite a few useful ones.

Friday, November 07, 2003

Multiple versions of Internet Explorer

There is a way of running several versions of Internet Explorer on one PC without resorting to dual booting. Details at Insert Title Web Designs. It looks like you can finally run IE5 on Windows XP for testing your HTML/CSS code.

The method is very simple and it illustrates the fact that Internet Explorer is not completely integrated into Windows. There is a set of zipped files available. I wonder why developers were never told about this?

Update - Jan 9 2004: Downloads now available at: Skyzyx downloads - Internet Explorer versions 3, 4, 5 and 5.5 available

Thursday, October 30, 2003

CSS

A table of CSS rules that you can apply to pages to hide CSS from certain browsers. Useful for working around CSS display bugs in certain browsers. CSS properties list is a list of CSS1/2 properties and which browsers they will work in (plus any quirks there might be)

Wednesday, October 29, 2003

Get File Size

This handy tool (download) enables you to find out the file size of a linked document within Internet Explorer. It also tells you when it was last modified.

CSS / XML Editors

Free CSS editor provided by Morphon (11.7MB download). Requires Java Runtime (or download a 24.8MB file which includes the runtime.)
There is also an XML editor available (13.3MB download, 28.4MB with runtime)

Saturday, October 18, 2003

DevGuru

DevGuru contains a quick reference guide for the following: ADO , ASP , CSS2 , HTML , Javascript , JetSQL , VBScript , WML , WMLScript , WSH , XHTML , XML DOM and XSLT.

Very comprehensive. Downloadable PDF versions for $10.

Friday, October 17, 2003

JavaScript Sites

Wednesday, October 08, 2003

Programming Tools (Open Source)

A few tools that I have used (with syntax highlighting for various languages - HTML, JavaScipt, CSS, C++, etc...):

Update (30 Nov 05): Added SynEdit, jEdit


Tags: ,

Wednesday, October 01, 2003

Redirect to secure site (ASP)

The following will redirect from http://www.domain.com/path/to/file.asp to https://www.domain.com/path/to/file.asp:

VBScript:
<%
If Request.ServerVariables("HTTPS") = "off" Then
    Response.Redirect("https://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("URL"))
End If
%>
JScript:
<%
if(Request.ServerVariables("HTTPS") == "off"){
    Response.Redirect("https://" + Request.ServerVariables("HTTP_HOST") + Request.ServerVariables("URL"))
}
%>

Tuesday, September 30, 2003

Open maximised window (JavaScript)

The following will open a maximised window, with scrollbars, menubar, but no toolbar (only works with links to pages on the same site - ../folder/file.htm or /folder/file.html not http://www.google.com - Access denied error will occur):

function showDocument(sDocURL){
	var newwin = window.open(sDocURL,'newwin','scrollbars=yes,toolbar=no,menubar=yes');
	newwin.window.moveTo(0,0);
	newwin.window.resizeTo(screen.availWidth,screen.availHeight);
	newwin.focus();
	return false;
}

Call function as follows: <a href="../folder/file.htm" onclick="showDocument(this.href); return false">File</a>
Will set focus on page and replace any existing page that was called in the same way.

Monday, September 29, 2003

Convert ASP page to Microsoft Word document

Insert the following at the top of an ASP page to convert it to a Word document (Word 97+ required on client desktop). It uses Microsoft Word's HTML parser to generate the page.

JScript:
<%@LANGUAGE="JSCRIPT" CODEPAGE="1252"%>
<%
Response.ContentType = "application/msword";
Response.AddHeader("Content-Disposition","attachment;filename=filename.doc");
%>
VBScript:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Response.ContentType = "application/msword"
Response.AddHeader "Content-Disposition","attachment;filename=filename.doc"
%>

Note that only the text will be saved if you save the file to disk (i.e. images will not be downloaded and embedded into the document)

Tuesday, September 23, 2003

CSS Design

css Zen Garden: The Beauty in CSS Design site layouts done in CSS - all images that are displayed on the page are defined in the style sheet. It shows that you can add images to pages using nothing but CSS.

Other CSS Sites:

Monday, September 22, 2003

Delete file (ASP)

Delete file using ASP JScript (pass filename on in form [hidden input called 'deletefile'] or QueryString [page.asp?deletefile=myfile.doc]):

<%
// delete file
var oFSO = Server.CreateObject("Scripting.FileSystemObject");
// get path to file (relative to current document)
sPathToFile = Server.MapPath("/path/to/upload/folder/"+Request("deletefile"));
// if file exists, delete it 
if(oFSO.FileExists(sPathToFile)) oFSO.DeleteFile(sPathToFile)
// file deleted
%>
Or using ASP VBScript
<%
' delete file
Dim oFSO, sPathToFile
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
' get path to file (relative to current document)
sPathToFile = Server.MapPath("/path/to/upload/folder/"&Request("deletefile"));
' if file exists, delete it 
If oFSO.FileExists(sPathToFile) Then oFSO.DeleteFile(sPathToFile)
' file deleted
%>

N.B. Folder must have modify permissions set for the Internet Guest Account (normally IUSR_MACHINENAME)

Connect to Database (ASP)

The following connects to a database with ASP JScript:

<%
// create connection
var oConn = Server.CreateObject("ADODB.Connection");
// open connection to database
oConn.Open(CONNECTION_STRING);
// generate SQL
sSQL = "SELECT * FROM tablename";
// create recordset from SQL
var oRS = oConn.Execute(sSQL);
// work with recordset
Response.Write(oRS("fieldname"));
// close recordset and connection
oRS.Close();
oConn.Close;
%>

And with ASP VBScript:

<%
Dim oConn, sSQL, oRS
' create connection
Set oConn = Server.CreateObject("ADODB.Connection")
' open connection to database
oConn.Open(CONNECTION_STRING)
' generate SQL
sSQL = "SELECT * FROM tablename"
' create recordset from SQL
Set oRS = oConn.Execute(sSQL)
' work with recordset
Response.Write(oRS("fieldname"))
' close recordset and connection
oRS.Close()
Set oRS = Nothing
oConn.Close()
Set oConn = Nothing
%>

Sunday, September 21, 2003

Folder Size Browser program

Found this .NET program that shows folder sizes for the various drives in My Computer: Folder Size Browser program.
.NET Framework Required

Folder Size Shell Extension adds to the properties dialog of all folders the amount of space that is used up - this is good, but a standalone utility (i.e. running off a floppy disk) will also be good.

Friday, September 19, 2003

Blogging

Blogger sites Blogging tools

Wednesday, September 10, 2003

ASP.NET Forums / Groups

Some ASP.NET discussion groups: Newgroups (via Google)

Friday, August 29, 2003

.NET Weblogs @ ASP.NET

.NET Weblogs @ ASP.NET - good weblog site with many bloggers.
Of interest is Datagrid Girl - using the datagrid in ASP.NET

Friday, August 22, 2003

Google Toolbar 2.0

Google Toolbar 2.0 is no longer beta: http://toolbar.google.com/ Features:
  • Search the web with Google from any site
  • New! Eliminate pop-up ads
  • New! Fill in forms with one click
  • New! Link a weblog to the page you're visiting
  • New! Restrict your search to pages located in a specific country
  • Search just within the pages of a site
  • Highlight search terms on a page

VBScript - Set Homepage (MSIE) / Add Notepad to Send To

The following will set up your homepage (in Internet Explorer) via a VBScript file. Create a blank text file called 'sethome.vbs'. Running it will change your default home page. Useful for setting the home page via a login script (or after some spyware may have changed your homepage).
Set WSHShell = WScript.CreateObject("WScript.Shell")

' home page URL
StartPage = "http://www.google.co.uk"
WSHShell.RegWrite "HKLM\Software\Microsoft\Internet Explorer\Main\Start Page", StartPage
WSHShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\Start Page", StartPage
This code will add notepad to the Send To menu (when you right click a file). Create a new file called 'sendtonotepad.vbs', containing the following code.
Set WSHShell = WScript.CreateObject("WScript.Shell")

Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")

sWinDir = oFSO.GetSpecialFolder(WindowsFolder)

sSendTo = WSHShell.SpecialFolders("SendTo")

Set oShortCut = WSHShell.CreateShortcut(sSendTo & "\Notepad.lnk")

With oShortCut
 .WindowStyle = 3
 .IconLocation = "notepad.exe, 0"
 .TargetPath = sWinDir&"\notepad.exe"
 .Save
End With
Should work with all versions of windows after 95 (95/98/ME/2k/XP) with Windows Scripting installed. The code will not run in a web page. To allow IE site visitors to set their homepage to the one they are on, simple paste the following into your page:
<!--[if IE]>
<a href="#" onClick="this.style.behavior='url(#default#homepage)';this.setHomePage(location.href);">Set this page as your default homepage</a>
<![endif]-->
The latest version of Windows Scripting (required) can be found here

Monday, August 11, 2003

Overflow PRE tag (HTML & CSS)

Text doesn't wrap with the <pre> tag, so you need to scroll horizontally if there is a lot of text on one line:
Nulla neque diam, accumsan nec, egestas non, facilisis sed, wisi.    Donec lacinia vestibulum arcu. Suspendisse ligula. Donec tortor. Maecenas pharetra eros at odio.
	Morbi feugiat tempus orci. Cras vitae tellus. Sed congue nonummy magna. In sed neque id nisl tempus congue.
Duis varius egestas tellus. Suspendisse potenti. Nunc rhoncus, eros eget malesuada rhoncus, mi purus pharetra eros, sit amet porta lectus tortor ac erat.
In hac habitasse platea dictumst.
However, if you wrap it as follows <pre style="overflow: auto; width: 100%">Text</pre> it adds scroll bars when needed:
Nulla neque diam, accumsan nec, egestas non, facilisis sed, wisi.    Donec lacinia vestibulum arcu. Suspendisse ligula. Donec tortor. Maecenas pharetra eros at odio.
	Morbi feugiat tempus orci. Cras vitae tellus. Sed congue nonummy magna. In sed neque id nisl tempus congue.
Duis varius egestas tellus. Suspendisse potenti. Nunc rhoncus, eros eget malesuada rhoncus, mi purus pharetra eros, sit amet porta lectus tortor ac erat.
In hac habitasse platea dictumst.
width and overflow has to be defined, else it will not work. It also does not work particulary well when there are not many lines of text (scroll bars get in the way [at least 3 line breaks recommended]):
Nulla neque diam, accumsan nec, egestas non, facilisis sed, wisi.    Donec lacinia vestibulum arcu. Suspendisse ligula. Donec tortor. Maecenas pharetra eros at odio.

Monday, August 04, 2003

File Functions (JScript):

Various JScript functions for manipulating files: They should all work whichever format you use for the folder (c:\webroot\folder\subfolder\ or /folder/subfolder/)

Get files (returned as enumerator):
/*
sFolder = which folder (e.g. '/folder/subfolder/', 'c:\webroot\folder\subfolder\')
return enumerator of files
*/
function getFiles(sFolder){ 
	// create filesystemobject
	var oFSO = Server.CreateObject("Scripting.FileSystemObject")
	// get folder object
	try{
		var oFolder = oFSO.getFolder((sFolder.indexOf("/")==-1)?sFolder:Server.MapPath(sFolder))
	}catch(e){
		// if error occurs return blank enumerator
		return new Enumerator()
	}
	// create enumerator for files
	var eFiles = new Enumerator(oFolder.Files)
	// return files list
	return eFiles
}
Get file name:
/*
sPTF = path to file, bExt = include extension, default yes
returns filename as string
*/
function getFileName(sPTF,bExt){ 
	// new method using filesystemobject
	if(bExt!=false) bExt = true // if bExt is not supplied, the default is to return the file with the extension
	// create filesystemobject
	var oFSO = Server.CreateObject("Scripting.FileSystemObject")
	/*  
	get file object
	---------------
	there is a method to get the file name by using oFSO.GetFileName(sPTF)
	but it does not check to see if the file exists
	this method returns blank string if the file does not exist
	*/
	try{
		var oFile = oFSO.GetFile((sPTF.indexOf("/")==-1)?sPTF:Server.MapPath(sPTF))
		
	}catch(e){
		// if error occurs return blank string
		return ""
	}
	// get file name
	sFileName = oFile.Name
	// return dot?
	sFileName = (bExt)?sFileName:sFileName.substr(0,sFileName.lastIndexOf('.'))
	return sFileName.replace("&","&amp;")
	/* // old method using string manipulation
	iFNB = sPTF.lastIndexOf("\\")+1
	// file name begins here (the last \ in the file path), 1 is added to the result because javascript is zero based
	// if iFNB returns 0 then the supplied path is an absolute one, it is therefor compensated for
	iFNB = (iFNB==0)?sPTF.lastIndexOf("/")+1:iFNB
	if(bExt){ // if we want the extension
		// substring begins at iFNB and ends at the end of the string
		return sPTF.substr(iFNB) // return file (with extension)
	}
	else{ // if we don't want the extension
		// substring begins at iFNB and ends at the position of the last dot
		return sPTF.substr(iFNB,sPTF.lastIndexOf('.')-iFNB) // remove extension - including '.'
	} // end if(bExt)
	*/
}
Get file extension:
/*
sPTF = path to file, bDot = include dot, default false
returns file extension as string
*/
function getFileExt(sPTF,bDot){
	if(bDot!=true) bDot = false // if bDot is not supplied, the default is to return the extension with no dot
	// return substring beginning before or after the final dot according to bDot
	return sPTF.substr(sPTF.lastIndexOf('.')+((!bDot)?1:0))
}
Remove file extension ('file.ext' becomes 'file'):
/*
sFN = filename
return filename without extension
*/
function rmFileExt(sFN){
	return sFN.substr(0, sFN.lastIndexOf("."))
}
Get file size: consists of two functions - one for getting the file size, and one for converting it (if you already know the size)
/*
sPTF = path to file
sFmt = size format (b, kb, mb) - automatic if undefined
nDP = number of decimal places - default 2 if undefined
returns file size as string
*/
function getFileSize(sPTF, sFmt, nDP){
	// create filesystemobject
	var oFSO = Server.CreateObject("Scripting.FileSystemObject")
	// get file object
	try{
		var oFile = oFSO.GetFile((sPTF.indexOf("/")==-1)?sPTF:Server.MapPath(sPTF))
	}catch(e){
		// if error occurs return blank string
		return ""
	}
	// get file size
	var nFileSize = parseInt(oFile.size)
	sFmt = String(sFmt).toLowerCase()
	return fmtFileSize(nFileSize, sFmt, nDP)
}

function fmtFileSize(nFileSize, sFmt, nDP){
	if(isNaN(nDP)) nDP = 2
	var sAppend = ""
	if(sFmt!="b"||sFmt!="kb"||sFmt!="mb"){
		if(nFileSize<1000){
			var sFmt = "b"; var sAppend = " bytes";
		}
		else if(nFileSize>999 && nFileSize<1000000){
			var sFmt = "kb"; var sAppend = " kb";
		}
		else{
			var sFmt = "mb"; var sAppend = " mb";
		}
	}else{var sAppend = " "+sFmt}
	if(sFmt=="b") return nFileSize + sAppend
	if(sFmt=="kb"){
		// divide by 1024 to get the size in kb
		nFileSize = nFileSize / 1024;
		// multiply by 10 to the power of nDP
		nFileSize = nFileSize * Math.pow(10,nDP);
		// round up/down the new file size, and divide to remove the power and return the correct value
		nFileSize = Math.round(nFileSize) / Math.pow(10,nDP);
		return nFileSize + sAppend;
	}
	if(sFmt=="mb"){
		// divide by 1024 twice to get the size in mb
		nFileSize = nFileSize / 1024 / 1024;
		// multiply by 10 to the power of nDP
		nFileSize = nFileSize * Math.pow(10,nDP);
		// round up/down the new file size, and divide to remove the power and return the correct value
		nFileSize = Math.round(nFileSize) / Math.pow(10,nDP);
		return nFileSize + sAppend;
	}
}
File last modified date:
/*
sPTF = path to file
returns last modified date of file as date string
*/
function getLastModified(sPTF){
	// create filesystemobject
	var oFSO = Server.CreateObject("Scripting.FileSystemObject")
	// get file object
	try{
		var oFile = oFSO.GetFile((sPTF.indexOf("/")==-1)?sPTF:Server.MapPath(sPTF))
	}catch(e){
		// if error occurs return blank string
		return ""
	}
	// get file last modified
	dtLastModified = new Date(oFile.DateLastModified)
	return dtLastModified.toLocaleString()
}
Get file type:
/*
sPTF = path to file
returns file type as string
*/
function getFileType(sPTF){
	// create filesystemobject
	var oFSO = Server.CreateObject("Scripting.FileSystemObject")
	// get file object
	try{
		var oFile = oFSO.GetFile((sPTF.indexOf("/")==-1)?sPTF:Server.MapPath(sPTF))
	}catch(e){
		// if error occurs return blank string
		return ""
	}
	// get file type
	return oFile.Type
}
Get title, get comment: This gets summary information (for windows 2000). [Right click file, properties, select summary tab]
function getComment(sPTF){
	sPTF = (sPTF.indexOf("/")==-1)?sPTF:Server.MapPath(sPTF)
	var objShell = Server.CreateObject("Shell.Application");
	objFolder = objShell.NameSpace(sPTF.substr(0,sPTF.lastIndexOf("\\")+1));
	if (objFolder != null){
		objFolderItem = objFolder.ParseName(getFileName(sPTF,true));
		if (objFolderItem != null){
			return objFolder.GetDetailsOf(objFolderItem, 5); // 14 for XP and .NET Server
		}
	}
}
function getTitle(sPTF){
	sPTF = (sPTF.indexOf("/")==-1)?sPTF:Server.MapPath(sPTF)
	var objShell = Server.CreateObject("Shell.Application");
	objFolder = objShell.NameSpace(sPTF.substr(0,sPTF.lastIndexOf("\\")+1));
	if (objFolder != null){
		objFolderItem = objFolder.ParseName(getFileName(sPTF,true));
		if (objFolderItem != null){
			return objFolder.GetDetailsOf(objFolderItem, 11); // 10 for XP and .NET Server
		}
	}
}

Tuesday, July 29, 2003

SQL: Date Searching

Just some useful tips for searching on date fields (Microsoft SQL Server 2000+):

You can use the LIKE operator to do a search:

SELECT * FROM [tablename] WHERE [datecolumn] LIKE '%Aug%2003%'

This would match everything that had August 2003 in datecolumn e.g. August 12 2003, August 18 2003

The other way is to use DATEPART as follows:

SELECT * FROM [tablename] WHERE DATEPART(month,[datecolumn]) = 8 AND DATEPART(year,[datecolumn]) = 2003

The final way is to use MONTH and YEAR:

SELECT * FROM [tablename] WHERE MONTH([datecolumn]) = 8 AND YEAR([datecolumn]) = 2003

N.B. If you use DATEPART, MONTH, or YEAR, the supplied value has to be numeric (8 instead of August)

Monday, July 28, 2003

Javascript: Remove Items from Array

I required some javascript for removing an item (or series of items) from an array. Thankfully, I found out how to do it from this thread in Google Groups.

e.g. (paste into HTML document):
<script language="javascript">
// this is the original array
var theArray = [17,2,5,675];
// these are the items I wish to remove from the array
var toRemove = [17,2];
// it can be done with one item only as well
// var toRemove = 5;

// adding it as a prototype object enables it to be used from any array
Array.prototype.removeItems = function(itemsToRemove) {

    if (!/Array/.test(itemsToRemove.constructor)) {
        itemsToRemove = [ itemsToRemove ];
    }

    var j;
    for (var i = 0; i < itemsToRemove.length; i++) {
        j = 0;
        while (j < this.length) {
            if (this[j] == itemsToRemove[i]) {
                this.splice(j, 1);
            } else {
                j++;
            }
        }
    }
}
theArray.removeItems(toRemove);
alert(theArray);
</script>

Thanks to Grant Wagner for this. It also can be applied to server-side ASP pages as well as client-side HTML (after setting JavaScript as the page language). However, there seems to be something wrong with an array of form elements (they are comma-space seperated i.e. "2, 5, 75, 120"), so it has to be split using var arItems = String(Request.Form("items")).split(", ")

NB. Array.splice is used, but is not supported by all browsers.

There is also a method of doing it without using splice (thanks to Dr John Stockton for this) in this thread. I have not implemented it yet - might use it as client side code.

var Delenda = [], j, n = 0, T, U // Undefined value

  for (j = 0 ; j < toRemove.length ; j++ )
    Delenda[toRemove[j]] = true                         // or 0 !

  for (j = 0 ; j < theArray.length ; j++ )     
    if ( Delenda[ T = theArray[j] ] === U ) theNewArray[n++] = T

Finally, there is a method using Regular Expressions (thanks go to Greg for this):
<script type='text/javascript'>
function removeVal(arr, valToRemove){
  // Normalize to a string like !val!!val!!val!
  var s = '!' + arr.join('!!') + '!';
  // Remove targeted values with delimiters
  s = s.replace(new RegExp('!' + valToRemove + '!', 'g'), '');
  // Remove delimiter added to end in step 1
  s = s.replace(/^!/, '');
  // Remove delimiter added to start in step 1
  s = s.replace(/!$/, '');
  // Convert to array
  return s.split('!!');
}

function test(){
  var arr = [2,1,2,2,5,7,12,15,21,2]; // Check case with end vals
  var s = arr.toString();
  arr = removeVal(arr, 2)
  alert(s + '\n' + arr.toString());
}
</script>

<button onclick='test()' />test()</button>

Friday, July 25, 2003

First Weblog - Toolbars

This weblog was set up using Google Toolbar BETA 2.0. Best feature of this is probably the popup blocker (no need for installing standalone software for doing the same thing, IE 5.5 and up only).

Some other useful toolbars: The Dictionary.com Toolbar is also very good - online dictionary and thesaurus search.

DevelopersDex Toolbar for developers in ASP, C#, SQL, VB and XML. Lots of examples, articles and tutorials are available in the DevelopersDex Site as well as the possibility to post to USENET (Newsgroups).

The toolbars for Internet Explorer only