[thelist] Javascript Error

Norman Bunn norman.bunn at craftedsolutions.com
Tue Dec 21 15:26:22 CST 2004


<script language="JavaScript" type="text/javascript">
    function build_string() {
        var myIndex = '-1';
        var search_string = '';
        for (element in window.document.megasearch) {
            myIndex = window.document.megasearch[element].selectedIndex;
            if (myIndex > 0) {
                if (window.document.megasearch[element].name == 'pot_size'){
                    search_string = search_string + ' ' + 
window.document.megasearch[element][myIndex].value + '\"';
                }
                else {
                    search_string = search_string + ' ' + 
window.document.megasearch[element][myIndex].value;
                }
                window.document.megasearch.Search.value = search_string;
            }
            myIndex = '-1';
        }
    }
</script>

Trying to create a quick search string from a series of drop-down lists 
and am getting an error on the line:

myIndex = window.document.megasearch[element].selectedIndex;

IE says it "is null or not an object" and FF say 
"window.document.megasearch[element] has no properties" (BTW, FF lets 
the code execute anyway, IE kills it).  I assume it is because some of 
the form elements do not have selected indicies.  Here is the start of 
the form:

<FORM METHOD="post" 
ACTION="http://www.carter-and-holmes.com/cgi-bin/miva?Merchant2/merchant.mv+" 
name="megasearch">
<INPUT TYPE="hidden" NAME="Store_Code" VALUE="CAHO">
<INPUT TYPE="hidden" NAME="Screen" VALUE="SRCH">
<INPUT TYPE="text" NAME="Search">
<select name="type" onChange="build_string()">
                <option value="" selected>No preference</option>
                <option value="cattleya">Cattleya</option>
                <option value="cymbidium">Cymbidium</option>
                <option value="dendrobium">Dendrobium</option>
                <option value="oncidium">Oncidium</option>
                <option value="paphiopedilum">Paphiopedilum</option>
                <option value="phalaenopsis">Phalaenopsis</option>
                <option value="phragmipedium">Phragmipedium</option>
                <option value="species">Other Species</option>
                <option value="vanda">Vanda</option>
</select>

Is there a quick way around this?

Norman - feeling rusty around Christmas...

-- 
---

Norman W. Bunn
norman.bunn at craftedsolutions.com
803.405.1008
----------------------------------------------
www.CraftedSolutions.com
Crafted Solutions, Inc.
Web Design & Development
Web Site Hosting & Custom Solutions
"Get the results the Internet promises;
 get the 'Net Result' from Crafted Solutions!"
----------------------------------------------




More information about the thelist mailing list