ohmErnie
asked on
javascript error when trying to use getElementById: 'null' is null or not an object?
I thought this was pretty simple. I have an ASP:Image named img_load. I have a javascript set up to run onclick. All I want to do is set the visibility to true. Simple right? But I'm getting a 'null' is null or not an object error when trying to do anything with my javascript object. The image is in an update panel. Does that make a difference? Is that what's causing my error?
<script type="text/javascript">
function show_wait()
{
var img;
img = document.getElementById("img_load");
img.visible = true;
}
</script>
ASKER
Well, when I look at the source code, I don't even see my image. Is that because I set it invisible in ASP?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<script type="text/javascript">
function show_wait()
{
var img;
img = document.getElementById("i mg_load");
img.style.display = 'block';
}
</script>
function show_wait()
{
var img;
img = document.getElementById("i
img.style.display = 'block';
}
</script>
should be
("visibility", "hidden");
("visibility", "hidden");
Yeah, if you set Visible=false on the server control, it won't even be rendered. What you need to do is set CSS to hide the image, but the HTML will remain.
The CSS attribute to use is display:none or display:block
The CSS attribute to use is display:none or display:block
It may also not be shown if you are using update panels... AJAX loaded html won't show in the source...
ASKER
That worked great. All I had to do was change my javascript to set the visibility back to "visible".
To get this "renamed" id on the server, you need to use the ClientID function of the control. I've used this in the past to easily make the switch.
<script type="text/javascript">
function show_wait()
{
var img;
img = document.getElementById('<
img.visible = true;
}
</script>