[thelist] Javascript Error
Norman Bunn
norman.bunn at craftedsolutions.com
Tue Dec 21 16:46:39 CST 2004
Matt Warden wrote:
>On Tue, 21 Dec 2004 16:26:22 -0500, Norman Bunn
><norman.bunn at craftedsolutions.com> wrote:
>
>
>><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>
>>
>>
>
>Norman,
>
>There are a number of problems with your script. I will take a stab at
>it, although I'm not certain I understand what you're trying to do.
>
>First, this line:
>
>for (element in window.document.megasearch) {
>
>You are currently trying to iterate over a form object. This doesn't
>make sense. I assume you are trying to iterate over the elements in
>the form. For taht, you need something like this:
>
>for (element in window.document.megasearch.elements) {
>
>So, not element references an element in the elements array of the
>form. Therefore,
>
>myIndex = window.document.megasearch[element].selectedIndex;
>
>Ought to become:
>
>myIndex = window.document.megasearch.elements[element].selectedIndex;
>
>myIndex refers now to the selected index of the form element. This
>doesn't make sense for anything but a select box, but I'll leave that
>be. That said, this line is incorrect as well:
>
>
>search_string = search_string + ' ' +
>window.document.megasearch[element][myIndex].value;
>
>This should become
>
>search_string = search_string + ' ' +
>window.document.megasearch.elements[element].options[myIndex].value;
>
>or, equivalently, and maybe a little easier to read line-wrapped:
>
>search_string += ' ';
>search_string += document.megasearch.elements[element].options[myIndex].value;
>
>This way, you are accessing the option object with the index equal to
>the selected index (i.e., the selected option) and getting its value
>property.
>
>
>Matt,
>
>
>
>Thanks for the feedback. Actually, I was trying to iterate over the
>form object and ask each element of the form object for its selected
>index. I was hoping that elements without selected indexes would be
>skipped (as FF does) and I would get my problem addressed this way. I
>will look into what you have provided and go from there.
>
>
>
>Thanks,
>
>
>
>Norman
>
>---
>
>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