View Full Version : I can’t pass properties to function

09-06-2011, 08:17 PM
Hi all!:) I can`t pass properties to function. It should be something easy, but there is no way. I’ve lost the whole day trying to do it, but in vain. :o

The error is “Esperaba un objeto“ (“an object expected”)

Could anyone help me please?

Here is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
html, body { height:100%; background-color: #00ffaa;}
body { margin:0; padding:0; overflow:hidden; }
#flashContent { width:100%; height:100%; }

<title>Showing and Hiding Elements with JavaScript</title>
<script type="text/javascript" src="EnvVars.js">
function changeVisibility(TR){
if (document.getElementById('flashContent2').style.visibility=="hidden") {
document.getElementById('flashContent2').style.visibility = "visible";
} else {
document.getElementById('flashContent2').style.visibility = "hidden";


<div id="flashContent2" style="position: absolute; top: 210px; left: 260px; ">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100" height="50" id="Ball" align="middle">
<param name="movie" value="Ball.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="transparent" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />

<a href="http://www.adobe.com/go/getflash">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />



<input type="button" onclick="changeVisibility('flashContent2')" value="Doesn't work">



09-06-2011, 08:33 PM
This may not be a complete solution but,
it is a necessary change . Make it like
this then ask more questions ....

<script type="text/javascript" src="EnvVars.js"></script>
<script type="text/javascript">
function changeVisibility(TR){

Mr J
09-06-2011, 09:28 PM
I notice also that you state the div id within the function and also pass it as a parameter.

If your going to pass the id to the function try

function changeVisibility(ID){
if (document.getElementById(ID).style.visibility=="hidden") {
document.getElementById(ID).style.visibility = "visible";
} else {
document.getElementById(ID).style.visibility = "hidden";

Old Pedant
09-06-2011, 09:28 PM

When you use src="xxx" to specify an external JS file, then any *CODE* you put between <script> and </script> will *ONLY* be executed if the external JS file fails to load.

In other words, the code becomes "just in case" code.

Davey is showing you that, by putting your code in a *SEPARATE* set of <script>...</script> tags it will run regardless of the external code.

Old Pedant
09-06-2011, 09:29 PM
Or even simpler:

function changeVisibility(ID){
var div = document.getElementById(ID);
div.style.visibility = div.style.visibility == "visible" ? "hidden" : "visible";

09-07-2011, 10:32 AM
Thank you all, now it works :thumbsup: