Click to See Complete Forum and Search --> : What's wrong with this JavaScript code?


Energon
06-05-2001, 02:39 PM
I have this code here in an html document:


<tr>
<td><b>Completed:</b></td>
<td>
<select name="completed" onChange="changeVisibility('divCompleted', this.options[this.selectedIndex].value)">
<option value="" selected>Any Completed and Not Completed</option>
<option value="yes">Completed Only</option>
<option value="no">Not Completed Only</option>
</select>
</td>
</tr>
<div id="divCompleted" style="visibility:visible">
<tr>
<td><b>Completion Date:</b></td>
<td><b>Not Available</b></td>
</tr>
<tr>
<td><b>Tech:</b></td>
<td><b>Not Available</b></td>
</tr>
</div>
<tr>


and here's the code for the javascript function, changeVisibility:


function changeVisibility(id, visibility)
{
document.write(visibility);
if(document.all) {
if(visibility == 'show' || visibility == "yes" || visibility == "")
xxxx("document.all." + id + ".style.visibility='visible';");
if(visibility == 'hide' || visibility == "no")
xxxx("document.all." + id + ".style.visibility='hidden';");
} else {
if(visibility == 'show' || visibility == "yes" || visibility == "")
xxxx("document.layers['" + id + "'].visibility='show';");
if(visibility == 'hide' || visibility == "no")
xxxx("document.layers['" + id + "'].visibility='hide';");
}
}


The error I get (in IE) is this:

document.all.divCompleted.style is null or ... I don't remember the very end of it, but it was something like saying it was empty or something... I've looked at my spelling through and through and that's not it... and all the code I'm using is stuff I wrote a little bit ago for the same basic situation, except that it worked with Radio Buttons rather than Select Boxes... and I don't remember changing anything other than it
being a select box now, so I'm really stumped by this...

hmm... it's not letting me put something

Energon
06-05-2001, 02:39 PM
k... up there, where it says xxxx(, it should be the eval function... but I can't post it for some reaons... :(

Bob54325
06-05-2001, 02:40 PM
Maybe that is the navigator thinge?

Energon
06-05-2001, 03:48 PM
The full error is this:

'document.all.divCompleted.style' is null or not an object... which makes me think that I spelled something wrong or left something out, but I honestly don't see anything wrong... :\

Dru Lee Parsec
06-05-2001, 04:19 PM
I'm thinking the line with this code:
this.options[this.selectedIndex].value
may be the problem. I usually just pass the form object to my functions and then the function pull the selected option out of the select object rather than trying to pass the object in that way..

In your function try putting in an alert line to show you what the values of id and visibility are. They may be null.

Energon
06-05-2001, 04:26 PM
output from the alert:

id = divCompleted and visibility = yes

so that's working okay... it's the eval that's crapping out (it gives me the error line of 68, which is the line xxxx("document.all." + id + ".style.visibility='hidden';") )

and if I do an alert to see what the value of document.all.divCompleted.style.visibility is, it says divCompleted = visible... so I'm not sure what's going on...

Energon
06-05-2001, 05:38 PM
Well, I said screw it and went with radio buttons... I had to redo how the table was laid out, but it works fine that way... :shrug: