Click here to read the latest newsletter!
Submit Your Site For Free!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions

DevWebProNL
FlashNewz
DevWebPro









The Latest Internet News
Add Headlines for your site


Spry - Checking For A Valid URL

By Raymond Camden
Expert Author
Article Date: 2007-02-27

There has been a UDF released for a while now that would check to see if a URL is valid. Ben wrote urlExists over a year ago.

Along with isValid(), you can check both the form and existence of a URL.

For the heck of it - I thought I'd make a quick demo in Spry showing how you can do without refreshing the browser. First take a quick look at the online demo:

http://ray.camdenfamily.com/demos/spryurlcheck/

Don't hit submit on the button, just enter a URL and click off of it. Do note that the you have to enter a valid URL before the server will check it. (So don't enter "toaster", enter "http://www.toaster.com".)

The code behind this is rather simple. First, look at the form field for URL:

<input type="text" name="homepage" id="homepage" onBlur="validateURL()"> <span id="urlcheckresult"></span>

I use an onBlur to call a JavaScript function. Also note the span next to the form field. validateURL is pretty simple:

function validateURL() {
    var url = $("homepage").value;
    if(url == '') return;
    Spry.Utils.updateContent('urlcheckresult','urlcheck.cfm?site='+encodeURI(url));
}


I grab the value of the URL and ensure it isn't blank. Next I use updateContent. This was added in the last Spry release. It is a simple way to load a new URL into a div or span. Here I'm simply pointing the span next to my form field to a server side file. The server side file is also rather simple. To cut down on the size I removed Ben's UDF:

<cfparam name="url.site" default="">
<style>
b.good {
    color: green;
}
b.sucky {
    color: red;
}

</style>

<cfif len(url.site) and isValid("url", url.site)>
    <cfif urlExists(url.site)>
      <cfoutput><b class="good">Valid URL!</b></cfoutput>
    <cfelse>
      <cfoutput><b class="sucky">Appears to be an invalid URL</b></cfoutput>
    </cfif>
</cfif>


The only thing that I don't like about this demo is the speed. Adobe made updateContent blocking, so you can't do anything while the page is loading. Of course, someone could easily add this to the Spry code.

Comments

Tag:

Digg | Reddit | Furl

About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.


Newsletter Archive | Article Archive | Submit Article | Advertising Information | About Us | Contact


DevWebProNL is an iEntry, Inc.® publication - 1998-2009 All Rights Reserved Privacy Policy and Legal