Hide Null or Empty Value Fields
Posted on September 29, 2009
Filed Under Code Snippets | 1 Comment
Hiding Search Forms Fields with Null Values from the Search String.
Have you ever wanted to reduce that long confusing looking and un-necessary search string in your “GET” type forms? In our line of work we may opt to use one of three primary tools in our projects; OpenRealty, UltimateIDX, or our home grown product we use on high end projects. Regardless of product, in each instance the search forms for the MLS Quick Search uses the form action type of “GET” and in doing so it passes the form value to the URL string for the query. But what happens when you have a null value or a field with NO value? Why bother to pass fields to your search string that have no value? Over time we noted that lengthy search strings regardless of empty values or not would reduce the response time for the results substantially when compared to shorter search strings.
This script was written to help in the reduction of processing burdens placed on servers for large search forms that use the GET method for form processing. It was designed in part to reduce the SQL search timeout issue common in Real Estate MLS Search forms that rely on the “GET” method to reduce the number of fields passed in the query string. If a search form field contains a NULL or no value it will not be passed on to the GET string.
With help from coder / blogger Greg Burghardt of Fundamental Disaster we hashed out this little snippet to achieve what we were after. The code has since been modified and has about 4 different variants in use but this one is the most true to the original.
You can download the snippet in a zip file from right here; SearchForms.zip
To use this script you should add a little php to display a variable in the body tag or you can simply permanently alter the body tag as follows;
EXAMPLE:
<body onload=”enableEmptyFields(document.something);”>
You must also add an onSubmit event handler (property) belonging to a Form object as follows:
EXAMPLE:
<form action=”the-name-of-your-script.php” method=”get” onsubmit=”disableEmptyFields(this);” name=”something”>
/* ############################### COPYRIGHT NOTICE BEGINS #############################
@ Copyright 2008 - 2009: WP Realty Team - Chad Broussard and Jared Ritchey
@ Copyright 2008: Greg Burghardt
@ Copyright URL: http://www.wprealty.org and http://fundamentaldisaster.blogspot.com/
@ Published by: Chad Broussard and Jared Ritchey
@ Scripting: In part by http://fundamentaldisaster.blogspot.com/ and Jared Ritchey Design
@ License: GNU / GPL
@ File Name: searchforms.js
############################### COPYRIGHT NOTICE ENDS ############################# */
/*
@ DISCLAIMER AND USAGE AND LICENSE:
You are free to use this script for whatever reason you so desire providing you leave the copyright details above in
tact as required and you do not redistribute this code rebranded as your own work. You are free to include this
code in any commercial or non-commercial application without further permission or obligation from WPRealty or
Chad Broussard. You may NOT republish this code absent of this copyright notice. LICENSED AS GNU/GPL Open Source
with provisions.
*/
function enableEmptyFields(form) {
var i = 0;
var field;
var j = 0;
var opt;
while (field = form.elements[i++]) {
switch (field.nodeName) {
case "input":
switch (field.type) {
case "checkbox":
case "radio":
field.disabled = !field.checked;
break;
default:
field.disabled = false;
break;
}
break;
case "select":
if (field.multiple) {
j = 0;
while (opt = field.options[j++]) {
opt.disabled = !opt.selected;
}
} else {
field.disabled = false;
}
break;
default:
field.disabled = false;
break;
}
}
}
function disableEmptyFields(form) {
var i = 0;
var field;
var j = 0;
var opt;
while (field = form.elements[i++]) {
switch (field.nodeName) {
case "input":
switch (field.type) {
case "checkbox":
case "radio":
field.disabled = !field.checked;
break;
default:
field.disabled = (field.value.length > 0) ? false : true;
break;
}
break;
case "select":
if (field.multiple) {
j = 0;
while (opt = field.options[j++]) {
opt.disabled = !opt.selected;
}
} else {
field.disabled = (field.value.length > 0) ? false : true;
}
break;
default:
field.disabled = (field.value.length > 0) ? false : true;
break;
}
}
}
Comments
Leave a Comment
If you would like to make a comment, please fill out the form below.
Recently
- Open-Realty® Moves To Commercial Model
- Aged Domains For Sale
- Break Time Away From This Business.
- I am taking a break from freelance
- OpenRealty Paid Support
- XML Feed Templates Download
- OpenRealty Data Icon Tutorial
- Recovering or Creating Joomla Administrator Account Password
- Hide Null or Empty Value Fields
- WP Menu Creator for Theme Developers
Categories
- Adobe Dreamweaver
- Announcements
- Code Snippets
- Design
- General
- Joomla CMS
- Portfolio
- Products
- Products in Review
- Professionals In Review
- Real Estate News
- Real Estate Scripts
- Real Estate Websites
- Technical Resources
- Template Design Kit
- WordPress Wisdom
Archives
- June 2010
- April 2010
- March 2010
- January 2010
- September 2009
- August 2009
- July 2009
- June 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
[...] Pass only actual values to your search string: If you have a search form that has for instance 15 or maybe 30 fields. In OpenRealty a null value fields still ends up in the query string and still gets processed, by eliminating this you increase search results speed. I have a script we developed that can be easily included to help with this. You can see it in action this persons site located at Connestee Falls Homes, Try and make a “Quick Search” and watch what happens to the search form, the fields that don’t pass values are grayed out and they do not end up as part of the search string. You can use this script free of charge in your own projects. You can read about it here in my post about Hiding Search Form Fields with Null Values. [...]