<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>dingobytes</title>
	<atom:link href="http://www.dingobytes.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dingobytes.com</link>
	<description>what your nephew can't make you</description>
	<pubDate>Tue, 28 Oct 2008 03:47:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>showMessage</title>
		<link>http://www.dingobytes.com/2008/10/27/showmessage/</link>
		<comments>http://www.dingobytes.com/2008/10/27/showmessage/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 03:47:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Tutorial]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[form]]></category>

		<category><![CDATA[message]]></category>

		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.dingobytes.com/?p=21</guid>
		<description><![CDATA[Having to mess with forms all the time, I was beginning to go crazy tweeking different messages. One for success, one for failure, one for help, etc.
I decided to try to combine some css with some javascript to make a nice reusable piece to display my form messages. Here is the fruit of that labor.
The [...]]]></description>
			<content:encoded><![CDATA[<p>Having to mess with forms all the time, I was beginning to go crazy tweeking different messages. One for success, one for failure, one for help, etc.</p>
<p>I decided to try to combine some css with some javascript to make a nice reusable piece to display my form messages. Here is the fruit of that labor.</p>
<p>The function is going to take three arguments. The first argument is a message and or list of messages. The second is the id of the node you would like to stick the message before. The last argument is a classname.</p>
<p><code><span style="color: #0000ff;">function</span> showMessage(thismessage,location_id,classname){<br />
<span style="color: #008000;">//	first clear showmessage div</span><br />
<span style="color: #0000ff;">if</span>(document.getElementById(<span style="color: #008000;">&#8220;showmessage&#8221;</span>)){<br />
<span style="color: #0000ff;">var</span> clearerror=document.getElementById(<span style="color: #008000;">&#8220;showmessage&#8221;</span>)<br />
clearerror.parentNode.removeChild(clearerror)<br />
}</code></p>
<p>The first part of the function will check to see if the div &#8220;showmessage&#8221; exists. If it does then it will remove it from the document.</p>
<p><code> <span style="color: #008000;">// create an showmessage div</span><br />
<span style="color: #0000ff;">var</span> location = document.getElementById(location_id);</code></p>
<p>We define the location so it can be used later. Below we create a new div and set the id attribute to showmessage. We then can style the div for each instance using the className. After that we create an unordered list.</p>
<p>With the list ready, the messages can then be put into an array. We will split the messages up in this example with a pipe &#8220;|&#8221;.  You can substitute your own delimiter.</p>
<p><code> <span style="color: #0000ff;">var</span> showmessagediv = document.createElement(<span style="color: #008000;">&#8220;div&#8221;</span>);<br />
showmessagediv.setAttribute(<span style="color: #008000;">&#8220;id&#8221;</span>,<span style="color: #008000;">&#8220;showmessage&#8221;</span>);<br />
showmessagediv.className = classname;<br />
<span style="color: #0000ff;">var</span> showmessageul = document.createElement(<span style="color: #008000;">&#8220;ul&#8221;</span>);<br />
showmessageul.setAttribute(<span style="color: #008000;">&#8220;id&#8221;</span>,classname+<span style="color: #008000;">&#8220;list&#8221;</span>);<br />
<span style="color: #0000ff;">var</span> showmessage = new Array();<br />
showmessage = </code><code>thismessage</code><code>.split(<span style="color: #008000;">&#8220;|&#8221;</span>);<br />
<span style="color: #0000ff;">for</span>(i=0; i<br />
<span style="color: #0000ff;">var</span> showmessageli = document.createElement(<span style="color: #008000;">&#8220;li&#8221;</span>);<br />
<span style="color: #0000ff;">var</span> showmessagelitxt = document.createTextNode(showmessage[i]);<br />
showmessageli.appendChild(showmessagelitxt);<br />
showmessageul.appendChild(showmessageli);<br />
}<br />
showmessagediv.appendChild(showmessageul);<br />
location.parentNode.insertBefore(showmessagediv,location);<br />
<span style="color: #008000;">//	have to add this to display error until css corrected</span><br />
}</code></p>
<p>Looping through the array, we create a new list element and insert the message. We append the message to the new list element and then append the list element to the unordered list element. When it is all done then we append the unordered list to the showmessage div. The last step of the function is to insert the new showmessage div right before the location_id.</p>
<p>Attached is the style I used with both the successful messages and the unsuccessfull images.</p>
<p><code><span style="color: #0000ff;">.errormsg</span> {<br />
clear: both;<br />
display: block;<br />
width: <span style="color: #0000ff;">90%</span>;<br />
color: <span style="color: #0000ff;">#FFFFFF</span>;<br />
font-weight: bold;<br />
background-color: <span style="color: #0000ff;">#FF9D9D</span>;<br />
padding: <span style="color: #0000ff;">9px 10px 6px 40px</span>;<br />
margin: <span style="color: #0000ff;">10px 0</span>;<br />
border: <span style="color: #0000ff;">2px</span> solid <span style="color: #0000ff;">#FF0000</span>;<br />
}</code></p>
<p><code><span style="color: #0000ff;">.successmsg</span> {<br />
clear: both;<br />
display: block;<br />
width: <span style="color: #0000ff;">90%</span>;<br />
color: <span style="color: #0000ff;">#333333</span>;<br />
font-weight: bold;<br />
background-color: <span style="color: #0000ff;">#9bc19b</span>;<br />
padding: <span style="color: #0000ff;">9px 10px 6px 40px</span>;<br />
margin: <span style="color: #0000ff;">10px 0</span>;<br />
border: <span style="color: #0000ff;">2px</span> solid <span style="color: #0000ff;">#039b03</span>;<br />
}</code></p>
<p><code>#errormsglist, #successmsglist {<br />
margin-left: <span style="color: #0000ff;">0</span>;<br />
padding-left: <span style="color: #0000ff;">0</span>;<br />
list-style: none;<br />
}</code></p>
<p><code>#errormsglist li, #successmsglist li{<br />
padding-left: <span style="color: #0000ff;">20px</span>;<br />
background-repeat: no-repeat;<br />
background-position: <span style="color: #0000ff;">0</span>;<br />
}</code></p>
<p><code>#errormsglist li { background-image: <span style="color: #0000ff;">url(/icon/exclamation.png)</span>; }</code></p>
<p><code>#successmsglist li { background-image: <span style="color: #0000ff;">url(/icon/accept.png)</span>; }</code></p>
<p>You can modify the CSS and change the class name to what ever you wish. The only think to remember is if you style the list, to append &#8220;list&#8221; to the style.</p>
<p><a href="http://www.dingobytes.com/wp-content/uploads/2008/10/showmessage.js">showMessage.js<br />
</a><a href="http://www.dingobytes.com/wp-content/uploads/2008/10/showmessage.css">showMessage.css<br />
</a></p>
<div id="attachment_28" class="wp-caption alignnone" style="width: 26px"><a href="http://www.dingobytes.com/wp-content/uploads/2008/10/exclamation.png"><img class="size-medium wp-image-28" title="exclamation.png" src="http://www.dingobytes.com/wp-content/uploads/2008/10/exclamation.png" alt="exclamation.png" width="16" height="16" /></a><p class="wp-caption-text">exclamation.png</p></div>
<div id="attachment_27" class="wp-caption alignnone" style="width: 26px"><a href="http://www.dingobytes.com/wp-content/uploads/2008/10/accept.png"><img class="size-medium wp-image-27" title="accept.png" src="http://www.dingobytes.com/wp-content/uploads/2008/10/accept.png" alt="accept.png" width="16" height="16" /></a><p class="wp-caption-text">accept.png</p></div>
<p><a href="http://www.dingobytes.com/wp-content/uploads/2008/10/showmessage.css"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dingobytes.com/2008/10/27/showmessage/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Setting up a new web site on centOS 5 box</title>
		<link>http://www.dingobytes.com/2008/10/03/web-site-on-centos-5-box/</link>
		<comments>http://www.dingobytes.com/2008/10/03/web-site-on-centos-5-box/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 02:43:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[Tutorial]]></category>

		<category><![CDATA[Apache]]></category>

		<category><![CDATA[directives]]></category>

		<category><![CDATA[Directory]]></category>

		<category><![CDATA[options]]></category>

		<category><![CDATA[setup]]></category>

		<category><![CDATA[VirtualHost]]></category>

		<category><![CDATA[web site]]></category>

		<guid isPermaLink="false">http://www.dingobytes.com/?p=16</guid>
		<description><![CDATA[There are so many great tutorials on the web about setting up a Linux box for web hosting, but  why not add one more&#8230; right? Actually this tutorial is written specifically for a co worker that is not familiar with Linux, so this tutorial is being offered to &#8220;assist&#8221; him with the migration process. [...]]]></description>
			<content:encoded><![CDATA[<p>There are so many great tutorials on the web about setting up a Linux box for web hosting, but  why not add one more&#8230; right? Actually this tutorial is written specifically for a co worker that is not familiar with Linux, so this tutorial is being offered to &#8220;assist&#8221; him with the migration process. His old hosting company provided him with CPanel and he is reluctant to change, but who in their right mind would pass up hosting at the price of &#8220;free ninty-nine&#8221;.</p>
<p><span id="more-16"></span>By no means is this a guide for all new linux user, but just a compilation of things learned while setting up web services on a Linux box in the past.</p>
<p>The first step, but not always a necessary step is setting up a new user. This is the preferred way to start as the /etc/skel has been preloaded with all the necessary directories and files to get new users started. If you are going to be a system administrator and you are not familiar with the /etc/skel/, please take some time learn more information about placing files in the /etc/skel/ directory to save time setting up new users. You can put default web directory such as www or public_html plus any other files and or directories you want to give to all new users.</p>
<p>To setup a new user you can simply use the following command (replace username with the username you want to use)</p>
<p><code>adduser -m <em>username</em></code></p>
<p>Now that you have created the account, it is best to setup a password for the account. You can assign  a password to the account using the following command</p>
<p><code>passwd <em>username</em></code></p>
<p>You should be prompted to enter in the new password and then confirm the password. Assume a new account needs to be setup with the username of ditto. When you run the passwd ditto command you should be prompted for the password as follows.</p>
<p><code>Changing password for user ditto.<br />
New UNIX password:<br />
Retype new UNIX password:</code></p>
<p>Your new account is almost ready to start putting files up for the web. One thing to pass along to new system administrators is that you have to make sure you setup the right permissions on this new account so it is strongly suggested that you do this now.</p>
<p>Now the path to the new account may differ depending on your server. Assume for now that new users are setup in the /home/ directory. Assuming your new user &#8220;ditto&#8221; was created successfully, the new account for ditto should be /home/ditto/. Any files in your /etc/skel/ directory would be there as well.  You can check this by using the following command to change directories and list the contents of the directory</p>
<p><code>cd /home/ditto &amp;&amp; ls</code></p>
<p>In this example we have two folders for our user ditto and they are the public_html and wwwconf directories.</p>
<p>To change the permissions on the users ditto directory so it can be viewed by visitors, the permissions on the ditto directory must be changed to something like 755. This can be done to just ditto directory using following command:</p>
<p><code>chmod 755 /home/ditto</code></p>
<p>If you don&#8217;t know what 755 is as far as permissions, pause this tutorial and take the time to <a title="Linux Command Directory: chmod" href="http://www.oreillynet.com/linux/cmd/cmd.csp?path=c/chmod" target="_blank">learn about chmod </a>and what the different permissions will do for you.</p>
<p>Now comes the part where many configurations likely differ depending on what you have installed to run on your server. This tutorial opts to save a core httpd related .conf file in one httpd directory (conf.d) and then from there look for more .conf files in the user directory called wwwconf/. This setup is not the only one possibility in the universe and if you have an older setup or wish to do it differently that is your choice.</p>
<p>You can start your .conf file by copying a current one or creating a new one in your httpd/conf.d/ directory. This tutorial will assume that directory is located at /etc/httpd/conf.d/. Creat your new .conf file in vi or vim by using the following command.</p>
<p><code>sudo vim web.ditto.com.conf</code></p>
<p>This is going to be the core configuration file for your virtualhost. You will need to start the virtualhost using the tag:</p>
<p><code>&lt;VirtualHost *:80&gt;</code></p>
<p>The VirutalHost directive is used to     enclose a group of directives which will apply only to a     particular virtual host. Inside this directive you will put all the information pertaining to your site. You can put the email address to your ServerAdmin, the absolute path to the Document Root, the ServerName and any ServerAlias</p>
<p><code>ServerAdmin webmaster@localhost<br />
Documentroot /home/ditto/public_html/<br />
ServerName www.ditto.com<br />
ServerAlias ditto.com</code></p>
<p>Now it is necessary to give Apache some directives that will apply to our public_html directory. To do this you will create another node inside the VirtualHost node named Directory. The Directory node here is used to enclose     a group of directives which will apply only to the named     directory and sub-directories of that directory (in this case the public_html directory).</p>
<p><code>&lt;Directory /home/ditto/public_html&gt;<br />
Options ExecCGI FollowSymLinks +Includes<br />
&lt;/Directory&gt;</code></p>
<p>This tells Apache that the execution of CGI scripts is permitted, the server will follow symbolic links in this directory, and that server-side includes are permitted.</p>
<p>You will also like to have some type of error log as is very useful when troubleshooting an issue on the box, so be sure to include the following code for error logging. You can access the logs in your httpd/logs directory</p>
<p><code>ErrorLog logs/ditto.error<br />
CustomLog logs/ditto.log combined</code></p>
<p>Now for the customized part. In order to let the user create their own Directory options another Directory directive is created that will point to a folder where other options/modifications can be made by the account user.</p>
<p><code>&lt;Directory /home/ditto/wwwconf&gt;<br />
AllowOverride All<br />
&lt;/Directory&gt;</code></p>
<p>What this does is allows ditto to ftp or ssh into the box and create a .conf file with their own directives and options in the wwwconf/ directory. The directive inside the above tag says any     directive which has the .htaccess context is allowed in .htaccess files. After this tag is closed, it can be followed up with</p>
<p><code>Include /home/ditto/wwwconf/*.conf</code></p>
<p>which tells Apache to grab any file with .conf in the wwwconf/ directory of ditto (if you didn&#8217;t know it already, the &#8220;*&#8221; is a wildcard here).</p>
<p>That should do it. You can now put an end to your VirtualHost node (if you have not already) and your end result should look something like</p>
<p><code>&lt;VirtualHost *:80&gt;<br />
ServerAdmin webmaster@localhost<br />
Documentroot /home/ditto/public_html/<br />
ServerName www.ditto.com<br />
ServerAlias ditto.com<br />
&lt;Directory /home/ditto/public_html&gt;<br />
Options ExecCGI FollowSymLinks +Includes<br />
&lt;/Directory&gt;<br />
ErrorLog logs/ditto.error<br />
CustomLog logs/ditto.log combined<br />
&lt;Directory /home/ditto/wwwconf&gt;<br />
AllowOverride All<br />
&lt;/Directory&gt;<br />
Include /home/ditto/wwwconf/*.conf<br />
&lt;/VirtualHost&gt;</code></p>
<p>You can now save this in the httpd/conf.d/ folder. Now if you want to add a mod re-wite or make a password protected directory in public_html, you can add a .conf file to the wwwconf directory and save my changes there. There is still one more command to use in order for all of this to work and that is the command to restart the httpd service. This can be done very easily using the following command.</p>
<p><code>service httpd restart</code></p>
<p>If you are running on an older system, this command may not be recognized. In those cases you should be able to use</p>
<p><code>/etc/init.d/httpd restart</code></p>
<p>Assuming you didn&#8217;t get any errors when you restarted the httpd service your web service should now be working. If you get an error, be sure to address it right away. Most common issues are invalid paths in the &lt;Directory&gt; tags or missing directories that the &lt;Directory&gt; tags are directed too.</p>
<p>Hopefully this tutorial was helpful to at least one user out there. This tutorial will be followed up next by a tutorial that will help you setup subdomains, create password protected directories and create mod rewrites.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dingobytes.com/2008/10/03/web-site-on-centos-5-box/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dealing with sendmail errors</title>
		<link>http://www.dingobytes.com/2008/08/19/dealing-with-sendmail-errors/</link>
		<comments>http://www.dingobytes.com/2008/08/19/dealing-with-sendmail-errors/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 07:18:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[550 Banned]]></category>

		<category><![CDATA[failure]]></category>

		<category><![CDATA[sendmail]]></category>

		<category><![CDATA[Service unavailable]]></category>

		<category><![CDATA[smtp auth]]></category>

		<guid isPermaLink="false">http://www.dingobytes.com/?p=9</guid>
		<description><![CDATA[I noticed last week that my emails were not being delivered properly. After taking a look at when the issue started, I realized that it was about the same time I updated my box.
My email was being returned with the reason: 550 Banned rcpt apache@localhost.localdomain. There was also another error 554 5.0.0 Service unavailable. Both [...]]]></description>
			<content:encoded><![CDATA[<p>I noticed last week that my emails were not being delivered properly. After taking a look at when the issue started, I realized that it was about the same time I updated my box.</p>
<p>My email was being returned with the reason: 550 Banned rcpt apache@localhost.localdomain. There was also another error 554 5.0.0 Service unavailable. Both of these errors on their own were not to helpful. I asked a friend (the one who sold me the box) to help and he gave me some good advice, but I was unable to resolve the issue and several Google searches didn&#8217;t reveal any solution.</p>
<p><span id="more-9"></span>I checked the maillog in /var/log/ and found that the mail was being sent internally, but I have to use my ISP mail server to actually deliver the messages and this was not happening. The error I found in the mail log that helped was &#8220;stat=Deferred: Temporary AUTH failure&#8221;. I was able to find the resolution to the issue right on the Sendmail.org site.</p>
<p>I use my sendmail as a client and up until last week I never had any issue with the setup I was using. I am still not sure if I began having an issue with sendmail because it was updated or if it was just my ISP found the security issue with the way I was using it, but eithr way, it stopped working correctly.</p>
<p>Here is the error:</p>
<p><code>----- The following addresses had permanent fatal errors -----<br />
&lt;apache@localhost.localdomain&gt;<br />
(reason: 550 Banned rcpt apache@localhost.localdomain *@localhost.localdomain)</code></p>
<p><code>----- Transcript of session follows -----<br />
... while talking to mail.cableone.net.:<br />
&gt;&gt;&gt; RCPT To:&lt;apache@localhost.localdomain&gt;<br />
&lt;&lt;&lt; 550 Banned rcpt apache@localhost.localdomain *@localhost.localdomain<br />
550 5.1.1 &lt;apache@localhost.localdomain&gt;... User unknown</code></p>
<p><code>Final-Recipient: RFC822; apache@localhost.localdomain<br />
Action: failed<br />
Status: 5.1.1<br />
Remote-MTA: DNS; mail.cableone.net<br />
Diagnostic-Code: SMTP; 550 Banned rcpt apache@localhost.localdomain *@localhost.localdomain<br />
Last-Attempt-Date: Mon, 18 Aug 2008 21:45:23 -0500</code></p>
<p><code>---------- Forwarded message ----------<br />
From: Mail Delivery Subsystem &lt;MAILER-DAEMON&gt;<br />
To: &lt;apache@localhost.localdomain&gt;<br />
Date: Mon, 18 Aug 2008 20:45:31 -0500<br />
Subject: Returned mail: see transcript for details<br />
----- The following addresses had permanent fatal errors -----<br />
&lt;support@cityofdilworth.com&gt;<br />
(reason: 550 Banned from (apache@localhost.localdomain) (*@localhost.localdomain))</code></p>
<p><code>----- Transcript of session follows -----<br />
... while talking to mail.cableone.net.:<br />
&gt;&gt;&gt; MAIL From:&lt;apache@localhost.localdomain&gt; SIZE=1521<br />
&lt;&lt;&lt; 550 Banned from (apache@localhost.localdomain) (*@localhost.localdomain)<br />
554 5.0.0 Service unavailable</code></p>
<p><code>Final-Recipient: RFC822; support@cityofdilworth.com<br />
Action: failed<br />
Status: 5.0.0<br />
Diagnostic-Code: SMTP; 550 Banned from (apache@localhost.localdomain) (*@localhost.localdomain)<br />
Last-Attempt-Date: Mon, 18 Aug 2008 20:45:31 -0500</code></p>
<p><code>---------- Forwarded message ----------</code></p>
<p>To resolve the issue, simply follow the instructions to setup SMTP AUTH that were provided by Benji Fisher. To start, log onto your machine as <code>root</code>.</p>
<ol>
<li>Change directory to where your sendmail configuration files <code>(sendmail.mc</code> and <code>sendmail.cf</code>) are located, usually<code> /etc/mail/</code></li>
<li>Create a safe subdirectory (suggested name <code>auth/</code>):<code># mkdir auth<br />
# chmod 700 auth</code></li>
<li>Create a file with your authentication information (suggested name <code>auth/client-info</code>):<br />
<code>AuthInfo:your.isp.net "U:root" "I:user" "P:password"</code></p>
<p>filling in your ISP&#8217;s mail server, your user name, and your password. (Note: Earthlink, and perhaps other ISP&#8217;s, requires your full e-mail address as a user name.)</li>
<li>Generate the authentication database and make both files readable only by <code>root</code>:<br />
<code># cd auth<br />
# makemap hash client-info &lt; client-info<br />
# chmod 600 client-info*<br />
# cd ..</code></li>
<li>Add the following lines to your <code>sendmail.mc</code> file, filling in your ISP&#8217;s mail server:<code>define(`SMART_HOST',`your.isp.net')dnl<br />
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl<br />
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl</code></li>
<li>Generate <code>sendmail.cf</code>:<code># m4 sendmail.mc &gt; sendmail.cf</code></li>
<li>Restart the sendmail daemon, e.g., (this depends on your OS):<code># service sendmail restart</code> or <code># /etc/init.d/sendmail restart</code></li>
</ol>
<p>That should take care of the issue!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dingobytes.com/2008/08/19/dealing-with-sendmail-errors/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Lame Mouse Over Effect</title>
		<link>http://www.dingobytes.com/2008/04/03/lame-mouse-over-effect/</link>
		<comments>http://www.dingobytes.com/2008/04/03/lame-mouse-over-effect/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 07:07:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Tutorial]]></category>

		<category><![CDATA[effect]]></category>

		<category><![CDATA[mouseover]]></category>

		<guid isPermaLink="false">http://www.dingobytes.com/?p=8</guid>
		<description><![CDATA[So at work today, I wanted to see if I could create a lame mouse over effect to let feel like they were highlighting a listing.  I wanted to pop out the moused over listing on the page by putting a thin border around the moused over div and then change the background. I [...]]]></description>
			<content:encoded><![CDATA[<p>So at work today, I wanted to see if I could create a lame mouse over effect to let feel like they were highlighting a listing.  I wanted to pop out the moused over listing on the page by putting a thin border around the moused over div and then change the background. I was able to create the effect with javascript and coldfusion very easily. Because I don&#8217;t host this site on a coldfusion server, I will just show the javascript with some rendered HTML.</p>
<p><span id="more-8"></span>To save some time, I will explain the javascript and how to call it. You can grab the css from the example page.</p>
<pre id="line149">&lt;<span class="start-tag">script</span><span class="attribute-name"> type</span>=<span class="attribute-value">"text/javascript"</span>&gt;
&lt;!--//

// function to change the background and border of listing on mouse over
function highlight_listing(id) {
if(id != 1) { //this is what to do for all divs other then first one
id_above = id - 1;
listing_el = document.getElementById("listing"+id);
listing_above_el = document.getElementById("listing"+id_above);
listing_above_el.style.border = "#ffffff 2px solid"; // removes border on result above highlighted
listing_el.style.backgroundColor = "#edfcd3";
listing_el.style.border = "#99cc33 2px solid";
}

else {
listing_el = document.getElementById("listing"+id);
listing_el.style.backgroundColor = "#edfcd3";
listing_el.style.border = "#99cc33 2px solid";
}
}

function listing(id) {
if(id != 1) {
id_above = id - 1;
listing_el = document.getElementById("listing"+id);
listing_above_el = document.getElementById("listing"+id_above);
listing_above_el.style.borderBottom = "#cccccc 2px dotted"; //restores border to result above highlighted
listing_el.style.backgroundColor = "#ffffff";
listing_el.style.border = "#ffffff 2px solid";
listing_el.style.borderBottom = "#cccccc 2px dotted";
}
else {
listing_el = document.getElementById("listing"+id);
listing_el.style.backgroundColor = "#ffffff";
listing_el.style.border = "#ffffff 2px solid";
listing_el.style.borderBottom = "#cccccc 2px dotted";
}
}
//--&gt;
&lt;/<span class="end-tag">script</span>&gt;</pre>
<p>The HTML can be spit through some query or loop and is straight forward.</p>
<p><code>&lt;div id="listing1" class="listing" onmouseover="javascript:highlight_listing('1');" onmouseout="javascript:listing('1');"&gt;<br />
&lt;div id="listing_top"&gt;<br />
&lt;span class="left"&gt;<br />
&lt;a href="javascript:void(0);" title="121 Initech Rd"&gt;121 Initech Rd&lt;/a&gt;<br />
&lt;/span&gt;<br />
&lt;/div&gt;<br />
&lt;div id="listing_left"&gt;<br />
&lt;a href="javascript:void(0);" title="121 Initech Rd"&gt;&lt;img src="images/inventory/thumbs/0/0/0/000976.jpg" alt="121 Initech Rd" class="displayed" width="151" /&gt;&lt;/a&gt;<br />
2.00 bed 3.00 bath 1296 sqft&lt;br /&gt;<br />
Lake Home&lt;br /&gt;<br />
Listing: 08-1979<br />
&lt;/div&gt;<br />
&lt;div id="listing_right"&gt;&lt;span class="large_price"&gt;$198699&lt;/span&gt; One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. "What's happened to me? " he thought. It wasn't a dream.&lt;/div&gt;<br />
&lt;div class="clear"&gt;&lt;/div&gt;<br />
&lt;/div&gt;</code></p>
<p><code>&lt;div id="listing2" class="listing" onmouseover="javascript:highlight_listing('2');" onmouseout="javascript:listing('2');"&gt;<br />
&lt;div id="listing_top"&gt;<br />
&lt;span class="left"&gt;<br />
&lt;a href="javascript:void(0);" title="121 Initech Rd"&gt;121 Initech Rd&lt;/a&gt;<br />
&lt;/span&gt;<br />
&lt;/div&gt;<br />
&lt;div id="listing_left"&gt;<br />
&lt;a href="javascript:void(0);" title="121 Initech Rd"&gt;&lt;img src="images/inventory/thumbs/0/0/0/000976.jpg" alt="121 Initech Rd" class="displayed" width="151" /&gt;&lt;/a&gt;<br />
2.00 bed 3.00 bath 1296 sqft&lt;br /&gt;<br />
Lake Home&lt;br /&gt;<br />
Listing: 08-1979<br />
&lt;/div&gt;<br />
&lt;div id="listing_right"&gt;&lt;span class="large_price"&gt;$198699&lt;/span&gt; His room, a proper human room although a little too small, lay peacefully between its four familiar walls. A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame. It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer.&lt;/div&gt;<br />
&lt;div class="clear"&gt;&lt;/div&gt;<br />
&lt;/div&gt;</code></p>
<p>This can be completed repeated and by dynamically changing the value <em>i</em> you can populate the results so that</p>
<p><code>&lt;div id="listing<em>i</em>&#8221; class=&#8221;listing&#8221; onmouseover=&#8221;javascript:highlight_listing(&#8217;<em>i</em>&#8216;);&#8221; onmouseout=&#8221;javascript:listing(&#8217;<em>i</em>&#8216;);&#8221;&gt;</code></p>
<p>You can see the <a title="finished product" href="http://www.dingobytes.com/example/results.html" target="_blank">finished product here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dingobytes.com/2008/04/03/lame-mouse-over-effect/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Coldfusion Image Rotator</title>
		<link>http://www.dingobytes.com/2008/03/03/coldfusion-image-rotator/</link>
		<comments>http://www.dingobytes.com/2008/03/03/coldfusion-image-rotator/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 19:15:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Coldfusion]]></category>

		<category><![CDATA[image]]></category>

		<category><![CDATA[rotator]]></category>

		<category><![CDATA[turorial]]></category>

		<guid isPermaLink="false">http://www.dingobytes.com/2008/03/03/coldfusion-image-rotator/</guid>
		<description><![CDATA[I was tasked a few months ago to rotate an image on a site randomly. Ordinarily this would not be an issue but the image was a css background image and I really didn&#8217;t have the ambition to rewrite the css and page html to do this. Thankfully my laziness paid off, because I found [...]]]></description>
			<content:encoded><![CDATA[<p>I was tasked a few months ago to rotate an image on a site randomly. Ordinarily this would not be an issue but the image was a css background image and I really didn&#8217;t have the ambition to rewrite the css and page html to do this. Thankfully my laziness paid off, because I found a solution while looking through some php code for wordpress.</p>
<p><span id="more-7"></span>I ran into this template that I liked, but wanted to change the header image. I changed it, uploaded it and refreshed the page, but NOTHING changed. I spent a good 5 minutes on this before checking the css to see what was going on. Instead of finding a path to an image in the css for the background, I found a path to a file named rotate.php. The script was written by Matt Mullenweg (<a href="http://photomatt.net/scripts/randomimage">http://photomatt.net/scripts/randomimage</a>) and seemed simple enough to me. What I liked about this script is that it didn&#8217;t require managing a bunch of images. If you want an image you simply stick it in a predefined directory and point to that directory.</p>
<p>I decided to rewrite this in coldfusion and within a few minutes I had a working. It is rather simple. Define your folder, define your extensions and define the url path to the folder and you are done. You will find the code below.</p>
<p><code><font size="2" color="#800000"><br />
&lt;cftry&gt;</font><br />
<font size="2" color="#808080">&lt;!&#8212;<br />created by Andrew Alba &gt;&gt; <a href="http://www.albawebstudio.com/">http://www.albawebstudio.com</a><br />This will grab images from specified folder and randomly display them<br />You will only need to modify the three variables below<br />&#8212;&gt;</font><br />
<font size="2" color="#808080"><br />
&lt;!&#8212; Insert the absolute path (with trailing slash) to the images.<br />&#8220;/home/mysite/public_html/images/&#8221; or &#8220;/www/mysite/web/images/random/&#8221;<br />If the images are in the same directory as<br />this script you can leave it as shown file<br />&#8212;&gt;<br />
</font><br />
<font size="2" color="#800000"><br />
&lt;cfset<font size="2"> folder = </font><font size="2" color="#0000ff">&#8220;#GetDirectoryFromPath(GetBaseTemplatePath())#&#8221;</font><font size="2" color="#800000">&gt;</font><br />
</font><br />
<font size="2" color="#808080">&lt;!&#8212; List of allowed extensions (separate with space) &#8212;&gt;</font><br /><font size="2" color="#800000">&lt;cfset</font><font size="2"> ext = </font><font size="2" color="#0000ff">&#8220;jpg jpeg png gif&#8221;</font><font size="2" color="#800000">&gt;</font><br />
<font size="2" color="#808080"><br />
&lt;!&#8212; Insert the URL to the folder that contains the images &#8212;&gt;<br /><font size="2" color="#800000">&lt;cfset</font><font size="2"> url_image_path = </font><font size="2" color="#0000ff">&#8220;http://www.homeshq.com/gfx/promotion/&#8221;</font><font size="2" color="#800000">&gt;</font><br />
</font><br />
<font size="2" color="#808080"><br />
&lt;!&#8212; do not edit below this point &#8212;&gt;<br />&lt;!&#8212; lets get the contents of the folder &#8212;&gt;<br /><font size="2" color="#800000">&lt;cfdirectory</font><font size="2"> </font><font size="2" color="#800000">directory=</font><font size="2" color="#0000ff">&#8220;#folder#&#8221;</font><font size="2"> </font><font size="2" color="#800000">action=</font><font size="2" color="#0000ff">&#8220;list&#8221;</font><font size="2"> </font><font size="2" color="#800000">name=</font><font size="2" color="#0000ff">&#8220;filelisting&#8221;</font><font size="2" color="#800000">&gt;</font><br />
</font><font size="2" color="#808080"><br />
&lt;!&#8212; pull just file names out of the list &#8212;&gt;<br /><font size="2" color="#800000">&lt;cfset</font><font size="2"> fileList = </font><font size="2" color="#0000ff">&#8220;&#8221;</font><font size="2" color="#800000">&gt;<br />
</font><font size="2" color="#800000">&lt;cfoutput</font><font size="2"> </font><font size="2" color="#800000">query=</font><font size="2" color="#0000ff">&#8220;filelisting&#8221;</font><font size="2" color="#800000">&gt;<br />
</font><font size="2" color="#800000">&lt;cfif</font><font size="2"> filelisting.type </font><font size="2" color="#0000ff">is</font><font size="2"> </font><font size="2" color="#0000ff">&#8220;file&#8221;</font><font size="2" color="#800000">&gt;<br />
</font><font size="2" color="#800000">&lt;cfset</font><font size="2"> fileList = </font><font size="2" color="#000066">listappend</font><font size="2">(fileList,filelisting.name)</font><font size="2" color="#800000">&gt;<br />
</font><font size="2" color="#800000">&lt;/cfif&gt;<br />
&lt;/cfoutput&gt;</font><br />
</font><br />
<font size="2" color="#808080"><br />
&lt;!&#8212; now we can create a new list of files &#8212;&gt;<br /><font size="2" color="#800000">&lt;cfset</font><font size="2"> new_fileList = </font><font size="2" color="#0000ff">&#8220;&#8221;</font><font size="2" color="#800000">&gt;<br />
</font><font size="2" color="#800000">&lt;cfloop</font><font size="2"> </font><font size="2" color="#800000">list=</font><font size="2" color="#0000ff">&#8220;#fileList#&#8221;</font><font size="2"> </font><font size="2" color="#800000">index=</font><font size="2" color="#0000ff">&#8220;i&#8221;</font><font size="2"> </font><font size="2" color="#800000">delimiters=</font><font size="2" color="#0000ff">&#8220;,&#8221;</font><font size="2" color="#800000">&gt;</font><br /><font size="2" color="#808080">  &lt;!&#8212; lets use our list of extensions to <br />weed out the files types we don&#8217;t want &#8212;&gt;<br /></font><font size="2" color="#808080">  &lt;!&#8212; now we grab just the extension &#8212;&gt;<br />
</font><br /><font size="2" color="#800000">  &lt;cfset</font><font size="2"> file_ext = </font><font size="2" color="#000066">listlast</font><font size="2">(i,</font><font size="2" color="#0000ff">&#8220;.&#8221;</font><font size="2">)</font><font size="2" color="#800000">&gt;</font><br /><font size="2" color="#808080">  &lt;!&#8212; if it finds file_ext is acceptable as per<br />
ext then it adds it to the array &#8212;&gt;</font><br /><font size="2" color="#800000">&lt;cfif</font><font size="2"> </font><font size="2" color="#000066">listfindnocase</font><font size="2">(ext,file_ext,</font><font size="2" color="#0000ff">&#8221; &#8220;</font><font size="2">)</font><font size="2" color="#800000">&gt;<br />
    </font><font size="2" color="#800000">&lt;cfset</font><font size="2"> new_fileList = </font><font size="2" color="#000066">listappend</font><font size="2">(new_fileList,i)</font><font size="2" color="#800000">&gt;<br />
  </font><font size="2" color="#800000">&lt;/cfif&gt;<br />
</font><font size="2" color="#800000">&lt;/cfloop&gt;</font><br />
</font><font size="2" color="#808080"><br />
&lt;!&#8212; now to choose random number from the list &#8212;&gt;<br /><font size="2" color="#800000">&lt;cfset</font><font size="2"> image_file =<br />
</font><font size="2" color="#000066">listgetat</font><font size="2">(new_fileList,</font><font size="2" color="#000066">randrange</font><font size="2">(</font><font size="2" color="#ff0a0a">1</font><font size="2">,</font><font size="2" color="#000066">listlen</font><font size="2">(new_fileList),</font><font size="2" color="#0000ff">&#8220;SHA1PRNG&#8221;</font><font size="2">),</font><font size="2" color="#0000ff">&#8220;,&#8221;</font><font size="2">)</font><font size="2" color="#800000">&gt;</font><br />
</font><font size="2" color="#800000"><br />
&lt;cflocation<font size="2"> </font><br /><font size="2" color="#800000">url=</font><font size="2" color="#0000ff">&#8220;#url_image_path##image_file#?rand=#randrange(1,999999999,&#8221;</font><font size="2" color="#800000">SHA1PRNG</font><font size="2" color="#0000ff">&#8220;)#&#8221;</font><br /><font size="2" color="#800000">addtoken=</font><font size="2" color="#0000ff">&#8220;no&#8221;</font><font size="2" color="#800000">&gt;</font><br />
</font><font size="2" color="#800000"><br />
&lt;cfcatch<font size="2"> </font><font size="2" color="#800000">type=</font><font size="2" color="#0000ff">&#8220;any&#8221;</font><font size="2" color="#800000">&gt;&lt;/cfcatch&gt;<br />
&lt;/cftry&gt;</font><br />
</font></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dingobytes.com/2008/03/03/coldfusion-image-rotator/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Form Validation II</title>
		<link>http://www.dingobytes.com/2008/02/05/form-validation-ii/</link>
		<comments>http://www.dingobytes.com/2008/02/05/form-validation-ii/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 04:48:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Tutorial]]></category>

		<category><![CDATA[AJAX]]></category>

		<category><![CDATA[forms]]></category>

		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.dingobytes.com/2008/02/05/form-validation-ii/</guid>
		<description><![CDATA[Continuing on from the first part of the tutorial, we are going to continue through the list of form elements in the order we setup. Next we work on the email address.

else if(document.getElementById(&#8220;email&#8221;).value==&#8221; &#124;&#124;
(document.getElementById(&#8220;email&#8221;).value!=&#8221; &#38;&#38;
!emailfilter.test(document.getElementById(&#8220;email&#8221;).value))){
document.getElementById(&#8220;error_msg&#8221;).childNodes[0].data=
&#8216;Please enter a valid e-mail address.&#8217;;
document.getElementById(&#8220;error_msg&#8221;).style.display = &#8220;block&#8221;;
document.getElementById(&#8220;email&#8221;).focus();
return false;
}
Notice how we handle the email value checking first to see if it [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing on from the first part of the tutorial, we are going to continue through the list of form elements in the order we setup. Next we work on the email address.</p>
<p><code><strong><font size="2" color="#0000c0"></p>
<p align="left">else<font size="2"> </font><strong><font size="2" color="#0000c0">if</font></strong><font size="2" color="#5c5c5c">(</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;email&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">value</font><font size="2" color="#5c5c5c">==</font><font size="2" color="#005c00">&#8221;</font><font size="2"> </font><font size="2" color="#5c5c5c">||<br />
(</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;email&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">value</font><font size="2" color="#5c5c5c">!=</font><font size="2" color="#005c00">&#8221;</font><font size="2"> </font><font size="2" color="#5c5c5c">&amp;&amp;<br />
!</font><font size="2">emailfilter</font><font size="2" color="#5c5c5c">.</font><font size="2">test</font><font size="2" color="#5c5c5c">(</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;email&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">value</font><font size="2" color="#5c5c5c">))){<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;error_msg&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">childNodes</font><font size="2" color="#5c5c5c">[</font><font size="2" color="#004080">0</font><font size="2" color="#5c5c5c">].</font><font size="2">data</font><font size="2" color="#5c5c5c">=<br />
</font><font size="2" color="#005c00">&#8216;Please enter a valid e-mail address.&#8217;</font><font size="2" color="#5c5c5c">;<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;error_msg&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">style</font><font size="2" color="#5c5c5c">.</font><font size="2">display </font><font size="2" color="#5c5c5c">=</font><font size="2"> </font><font size="2" color="#005c00">&#8220;block&#8221;</font><font size="2" color="#5c5c5c">;<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;email&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">focus</font><font size="2" color="#5c5c5c">();<br />
</font><strong><font size="2" color="#0000c0">return</font></strong><font size="2"> </font><font size="2" color="#800040">false</font><font size="2" color="#5c5c5c">;<br />
}</font></p>
<p></font></strong></code>Notice how we handle the email value checking first to see if it is empty to trigger an error and then using the logical operator OR (denoted as ||), we then look at another statement. In that statement we use the logical operator AND (denoted as &amp;&amp;) to trigger an error, and if both the email filed is not empty and the emailfilter.test is not valid then we do what is in between the curly brackets again. The contents are the same as what we described in the first statement.</p>
<p><span id="more-3"></span></p>
<p><code><strong><font size="2" color="#0000c0"></p>
<p align="left">else<font size="2"> </font><strong><font size="2" color="#0000c0">if</font></strong><font size="2" color="#5c5c5c">(</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;phone&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">value</font><font size="2" color="#5c5c5c">!=</font><font size="2" color="#005c00">&#8220;&#8221;</font><font size="2"> </font><font size="2" color="#5c5c5c">&amp;&amp;<br />
!</font><font size="2">phonefilter</font><font size="2" color="#5c5c5c">.</font><font size="2">test</font><font size="2" color="#5c5c5c">(</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;phone&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">value</font><font size="2" color="#5c5c5c">)){<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;error_msg&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">childNodes</font><font size="2" color="#5c5c5c">[</font><font size="2" color="#004080">0</font><font size="2" color="#5c5c5c">].</font><font size="2">data </font><font size="2" color="#5c5c5c">=<br />
</font><font size="2" color="#005c00">&#8220;Please enter valid phone number&#8221;</font><font size="2" color="#5c5c5c">;<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;error_msg&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">style</font><font size="2" color="#5c5c5c">.</font><font size="2">display </font><font size="2" color="#5c5c5c">=</font><font size="2"> </font><font size="2" color="#005c00">&#8220;block&#8221;</font><font size="2" color="#5c5c5c">;<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;phone&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">focus</font><font size="2" color="#5c5c5c">();<br />
</font><strong><font size="2" color="#0000c0">return</font></strong><font size="2"> </font><font size="2" color="#800040">false</font><font size="2" color="#5c5c5c">;<br />
}</font></p>
<p></font></strong></code>The phone is very similar to the email, but nothing is done if no phone number is entered.</p>
<p><code><strong><font size="2" color="#0000c0"></p>
<p align="left">else<font size="2"> </font><strong><font size="2" color="#0000c0">if</font></strong><font size="2" color="#5c5c5c">(</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;subject&#8221;</font><font size="2" color="#5c5c5c">).<br />
</font><font size="2">options</font><font size="2" color="#5c5c5c">[</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">"subject"</font><font size="2" color="#5c5c5c">).</font><font size="2">selectedIndex</font><font size="2" color="#5c5c5c">].</font><font size="2">value</font><font size="2" color="#5c5c5c">==</font><font size="2" color="#005c00">&#8221;</font><font size="2" color="#5c5c5c">){<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;error_msg&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">childNodes</font><font size="2" color="#5c5c5c">[</font><font size="2" color="#004080">0</font><font size="2" color="#5c5c5c">].</font><font size="2">data</font><font size="2" color="#5c5c5c">=<br />
</font><font size="2" color="#005c00">&#8216;Please choose a subject address.&#8217;</font><font size="2" color="#5c5c5c">;<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;error_msg&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">style</font><font size="2" color="#5c5c5c">.</font><font size="2">display </font><font size="2" color="#5c5c5c">=</font><font size="2"> </font><font size="2" color="#005c00">&#8220;block&#8221;</font><font size="2" color="#5c5c5c">;<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;subject&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">focus</font><font size="2" color="#5c5c5c">();<br />
</font><strong><font size="2" color="#0000c0">return</font></strong><font size="2"> </font><font size="2" color="#800040">false</font><font size="2" color="#5c5c5c">;<br />
}</font></p>
<p></font></strong></code>The subject is a handled a little differently as it is part of a select element. You will notice that the format in the IF statement changes to read the chosen value. Giving the default a value=&#8221;" allows the application to recognize when no subject is selected.</p>
<p><code><strong><font size="2" color="#0000c0"></p>
<p align="left">else<font size="2"> </font><strong><font size="2" color="#0000c0">if</font></strong><font size="2" color="#5c5c5c">(</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;content&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">value</font><font size="2" color="#5c5c5c">==</font><font size="2" color="#005c00">&#8221;</font><font size="2" color="#5c5c5c">){<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;error_msg&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">childNodes</font><font size="2" color="#5c5c5c">[</font><font size="2" color="#004080">0</font><font size="2" color="#5c5c5c">].</font><font size="2">data</font><font size="2" color="#5c5c5c">=</font><font size="2" color="#005c00">&#8216;Please be sure to enter comments.&#8217;</font><font size="2" color="#5c5c5c">;<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;error_msg&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">style</font><font size="2" color="#5c5c5c">.</font><font size="2">display </font><font size="2" color="#5c5c5c">=</font><font size="2"> </font><font size="2" color="#005c00">&#8220;block&#8221;</font><font size="2" color="#5c5c5c">;<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;content&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">focus</font><font size="2" color="#5c5c5c">();<br />
</font><strong><font size="2" color="#0000c0">return</font></strong><font size="2"> </font><font size="2" color="#800040">false</font><font size="2" color="#5c5c5c">;<br />
}</font><strong><font size="2" color="#0000c0">else</font></strong><font size="2"> </font><font size="2" color="#5c5c5c">{</font><font size="2"> </font><strong><font size="2" color="#0000c0">return</font></strong><font size="2"> </font><font size="2" color="#800040">true</font><font size="2" color="#5c5c5c">;</font><font size="2"> </font><font size="2" color="#5c5c5c">}<br />
}<br />
</font><font size="2" color="#008000">//&#8211;&gt;<br />
</font><font size="2" color="#0000ff">&lt;/</font><font size="2" color="#a31515">script</font><font size="2" color="#0000ff">&gt;</font></p>
<p></font></strong></p>
<p align="left">The last item for textarea element is similar to what was done for the name element, and that is all followed the last ELSE which will return a true or you can have it point to another function (like we will do for AJAX call in the final example). If set to true, it will just submit the form.</p>
<p></code>So now that the script is done, the only thing left is providing a place to display the error. The div/span can be placed where ever you want the error to be displayed. The error will only be displayed when triggered by the javascript.</p>
<p><code><font size="2" color="#0000ff">&lt;<font size="2" color="#a31515">span</font><font size="2"> </font><font size="2" color="#ff0000">id</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;error_msg&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">class</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;errormssg&#8221;&gt;</font><font size="2"> </font><font size="2" color="#0000ff">&lt;/</font><font size="2" color="#a31515">span</font><font size="2" color="#0000ff">&gt;</font></p>
<p></font></code>The trick here is when the id error_message style is defined. The key will be to make the class display none. The javascript will trigger the error to be visible (by changing display:block;) and then the error can be changed back by simply changing the style for id=&#8221;error_msg&#8221; display:block.</p>
<p>So lets take a look at the finished project. You can view and copy the <a href="http://www.dingobytes.com/example/testform.html" title="Example Form">finished product here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dingobytes.com/2008/02/05/form-validation-ii/feed/</wfw:commentRss>
		</item>
		<item>
		<title>client side form validation</title>
		<link>http://www.dingobytes.com/2008/01/30/hello-world/</link>
		<comments>http://www.dingobytes.com/2008/01/30/hello-world/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 01:22:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Tutorial]]></category>

		<category><![CDATA[forms]]></category>

		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.dingobytes.com/?p=1</guid>
		<description><![CDATA[The more we learn the more fun we have. Take for example the simple process of validating a form. We can save the user a lot of time validating the form on the client side and still do it without those annoying alerts that pop up with a loud DING! It is rather easy with [...]]]></description>
			<content:encoded><![CDATA[<p>The more we learn the more fun we have. Take for example the simple process of validating a form. We can save the user a lot of time validating the form on the client side and still do it without those annoying alerts that pop up with a loud DING! It is rather easy with the help of a little javascript.</p>
<p>Now depending on what type of data you are passing to the server with your form, you will often need to also validate your fields data on the server too. This tutorial will only look at the client side validation, leaving server side validation to another tutorial at some other time.</p>
<p>Lets first start with our form. We are going to do a simple form that just asks for name, email address, optional phone number, a select list for subject and text area for message. Oh, I always forget, we need a submit and clear button too. Lets start it all of with our form tag.</p>
<p><span id="more-1"></span></p>
<p>The form tag <code>&lt;form&gt;</code> will typically have the standard attributes of a method (get or post) and some sort of action. I often use AJAX to process my forms so the action may simply be action=&#8221;#&#8221; or action =&#8221;javascript:void();&#8221;. Knowing that we will be validating this form we are going to add one more attribute to the form element to validate the form when it is submitted and it is obviously called onsubmit. Here is the tag we will be using.</p>
<p><code><font size="2" color="#0000ff"></p>
<p align="left">&lt;<font size="2" color="#a31515">form</font><font size="2"> </font><font size="2" color="#ff0000">action</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;javascript:void(0);&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">name</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;myform&#8221;<br />
</font><font size="2" color="#ff0000">onsubmit</font><font size="2">=&#8221;</font><strong><font size="2" color="#0000c0">return</font></strong><font size="2"> validateForm</font><font size="2" color="#5c5c5c">();</font><font size="2">&#8220;</font><font size="2" color="#0000ff">&gt;</font></p>
<p></font></code>If you look what is inside the onsubmit attribute, it is pretty straight forward, we want to return the result of the javascript function we are going to create called validateForm() so that if it is true the form will will submit and if it is false it will not send.</p>
<p>Next we are going to just briefly go over the other form elements. There are several other elements, but for todays tutorial we are only going to use the &lt;input&gt;, &lt;select&gt; and &lt;textarea&gt; elements. The one thing to remember whenever using these elements is they should always have a name and id attribute and the input element should have a type attribute as well. Here is a an example of one of the input elements (for email) and our select and textarea elements.</p>
<p><code><font size="2" color="#0000ff"></p>
<p align="left">&lt;<font size="2" color="#a31515">label</font><font size="2"> </font><font size="2" color="#ff0000">for</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;name&#8221;&gt;</font><font size="2">Name:</font><font size="2" color="#0000ff">&lt;/</font><font size="2" color="#a31515">label</font><font size="2" color="#0000ff">&gt;<br />
&lt;</font><font size="2" color="#a31515">input</font><font size="2"> </font><font size="2" color="#ff0000">type</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;text&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">id</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;name&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">name</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;name&#8221;</font><font size="2"> </font><font size="2" color="#0000ff">/&gt;<br />
&lt;</font><font size="2" color="#a31515">label</font><font size="2"> </font><font size="2" color="#ff0000">for</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;email&#8221;&gt;</font><font size="2">Email:</font><font size="2" color="#0000ff">&lt;/</font><font size="2" color="#a31515">label</font><font size="2" color="#0000ff">&gt;<br />
&lt;</font><font size="2" color="#a31515">input</font><font size="2"> </font><font size="2" color="#ff0000">type</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;text&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">id</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;email&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">name</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;email&#8221;</font><font size="2"> </font><font size="2" color="#0000ff">/&gt;<br />
&lt;</font><font size="2" color="#a31515">label</font><font size="2"> </font><font size="2" color="#ff0000">for</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;phone&#8221;&gt;</font><font size="2">Phone:</font><font size="2" color="#0000ff">&lt;/</font><font size="2" color="#a31515">label</font><font size="2" color="#0000ff">&gt;<br />
&lt;</font><font size="2" color="#a31515">input</font><font size="2"> </font><font size="2" color="#ff0000">type</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;text&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">id</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;phone&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">name</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;phonel&#8221;</font><font size="2"> </font><font size="2" color="#0000ff">/&gt;<br />
&lt;</font><font size="2" color="#a31515">label</font><font size="2"> </font><font size="2" color="#ff0000">for</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;subject&#8221;&gt;</font><font size="2">Subject:</font><font size="2" color="#0000ff">&lt;/</font><font size="2" color="#a31515">label</font><font size="2" color="#0000ff">&gt;<br />
&lt;</font><font size="2" color="#a31515">select</font><font size="2"> </font><font size="2" color="#ff0000">id</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;subject&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">name</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;subject&#8221;&gt;<br />
&lt;</font><font size="2" color="#a31515">option</font><font size="2"> </font><font size="2" color="#ff0000">value</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;Advertising Inquiry&#8221;&gt;</font><font size="2">Advertising Inquiry</font><font size="2" color="#0000ff">&lt;/</font><font size="2" color="#a31515">option</font><font size="2" color="#0000ff">&gt;<br />
&lt;</font><font size="2" color="#a31515">option</font><font size="2"> </font><font size="2" color="#ff0000">value</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;Support Inquiry&#8221;&gt;</font><font size="2">Support Inquiry</font><font size="2" color="#0000ff">&lt;/</font><font size="2" color="#a31515">option</font><font size="2" color="#0000ff">&gt;<br />
&lt;</font><font size="2" color="#a31515">option</font><font size="2"> </font><font size="2" color="#ff0000">value</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;General Inquiry&#8221;&gt;</font><font size="2">General Inquiry</font><font size="2" color="#0000ff">&lt;/</font><font size="2" color="#a31515">option</font><font size="2" color="#0000ff">&gt;<br />
&lt;/</font><font size="2" color="#a31515">select</font><font size="2" color="#0000ff">&gt;<br />
&lt;</font><font size="2" color="#a31515">label</font><font size="2"> </font><font size="2" color="#ff0000">for</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;message&#8221;&gt;</font><font size="2">Message:</font><font size="2" color="#0000ff">&lt;/</font><font size="2" color="#a31515">label</font><font size="2" color="#0000ff">&gt;<br />
&lt;</font><font size="2" color="#a31515">textarea</font><font size="2"> </font><font size="2" color="#ff0000">id</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;message&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">name</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;message&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">rows</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">cols</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;&#8221;&gt;&lt;/</font><font size="2" color="#a31515">textarea</font><font size="2" color="#0000ff">&gt;<br />
&lt;</font><font size="2" color="#a31515">input</font><font size="2"> </font><font size="2" color="#ff0000">type</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;submit&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">id</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;submit&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">name</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;submit&#8221;</font><font size="2"> </font><font size="2" color="#ff0000">value</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;Submit&#8221;</font><font size="2"> </font><font size="2" color="#0000ff">/&gt;</font></p>
<p></font></p>
<p align="left">Now that the form is created, we can move on to the javascript function to validate the form. You will want to place this javascript before the form in the page. Here is the code, I will explain it as we go through it.</p>
<p></code><code><font size="2" color="#0000ff"></p>
<p align="left">&lt;<font size="2" color="#a31515">script</font><font size="2"> </font><font size="2" color="#ff0000">type</font><font size="2">=</font><font size="2" color="#0000ff">&#8220;text/javascript&#8221;&gt;<br />
</font><font size="2" color="#008000">&lt;!&#8211;//<br />
</font><strong><font size="2" color="#0000c0">function</font></strong><font size="2"> validateForm</font><font size="2" color="#5c5c5c">(){<br />
</font><strong><font size="2" color="#0000c0">var</font></strong><font size="2"> emailfilter </font><font size="2" color="#5c5c5c">=<br />
</font><font size="2" color="#800040">/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/</font><font size="2" color="#5c5c5c">;<br />
</font><strong><font size="2" color="#0000c0">var</font></strong><font size="2"> phonefilter </font><font size="2" color="#5c5c5c">=<br />
</font><font size="2" color="#800040">/\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/</font><font size="2" color="#5c5c5c">;<br />
</font><strong><font size="2" color="#0000c0">if</font></strong><font size="2" color="#5c5c5c">(</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;name&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">value</font><font size="2" color="#5c5c5c">==</font><font size="2" color="#005c00">&#8220;&#8221;</font><font size="2" color="#5c5c5c">){<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;error_msg&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">childNodes</font><font size="2" color="#5c5c5c">[</font><font size="2" color="#004080">0</font><font size="2" color="#5c5c5c">].</font><font size="2">data </font><font size="2" color="#5c5c5c">=<br />
</font><font size="2" color="#005c00">&#8220;Please enter full name&#8221;</font><font size="2" color="#5c5c5c">;<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;error_msg&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">style</font><font size="2" color="#5c5c5c">.</font><font size="2">display </font><font size="2" color="#5c5c5c">=</font><font size="2"> </font><font size="2" color="#005c00">&#8220;block&#8221;</font><font size="2" color="#5c5c5c">;<br />
</font><font size="2">document</font><font size="2" color="#5c5c5c">.</font><font size="2">getElementById</font><font size="2" color="#5c5c5c">(</font><font size="2" color="#005c00">&#8220;name&#8221;</font><font size="2" color="#5c5c5c">).</font><font size="2">focus</font><font size="2" color="#5c5c5c">();<br />
</font><strong><font size="2" color="#0000c0">return</font></strong><font size="2"> </font><font size="2" color="#800040">false</font><font size="2" color="#5c5c5c">;<br />
}</font></p>
<p></font></code>The first thing we did was declare that we were going to use javascript by using the &lt;script&gt; tag. We then defined the function validateForm() which will have no values passed to it and use the curly brackets to hold our statements for the function.</p>
<p>Two regular expressions (regex) are then defined which will be used for validatig the email address and the pone number. I have created these two regex items, but you can find about any regex you could imagine at <a href="http://www.regexlib.com">http://www.regexlib.com</a>.</p>
<p>The next steps are going to be repeated in slightly different ways, so we will discuss them here in a little more detail. The first statement starts with the IF statement where we check to see if what is inside the () is true. If the statement is true it continues to process what is in the curly brackets.</p>
<p>The text on the right hand side of the first statement replaces the childNodes.data of the element with id=&#8221;error_message&#8221;. This is followed by style change of the element, in this example we change display:none to display:block.</p>
<p>To make it less confusing for the user, the next statement focuses the cursor back in the input field with id =&#8221;name&#8221;.  The last item in the IF statement is return false which will stop the form from processing. The IF statement is then closed with the end curly bracket.</p>
<p> To be continued. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dingobytes.com/2008/01/30/hello-world/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
