...

View Full Version : onclick doesn't seem to work without an alert()



dugjason
08-28-2008, 11:48 AM
My javascript function below is written to control the visibility of the "next" and "previous" buttons used to page through an image gallery (eg. showing images 1-10 of 50. press next to show 11-20 etc.)

When I remove the alert("!"); it will no longer hide and show the next/previous buttons as it does with the alert("!"). It does however seems to work OK when I do include the alert("!"), which is a pain as obviously it pops up every time you move to the next page.

javascript Code:


<script type="text/javascript">

function hideShow(x, hv, imgno) {
alert("!");
if (x == "next" && hv < 8) {
document.getElementById(x).style.visibility="hidden";
}
if (x == "previous" && imgno <= 9) {
document.getElementById(x).style.visibility="hidden";
}
}
</script>




Below is the HTML that calls the javascript:

Code:


<div id="previous" onclick="hideShow('previous',hv,imgno)">
<a href="#" class="nav_r" onclick="document.location.href='MY_URL'; return false;">Previous</a>
</div>
<div id="next" onclick="hideShow('next',hv,imgno)">
<a href="#" class="nav_r" onclick="document.location.href='MY_URL'; return false;">Next</a>
</div>



Any help will be greatly appreciated

rubenbuhr
08-29-2008, 03:55 AM
<a href="#" class="nav_r" onclick="document.location.href='MY_URL'; return false;">Previous</a>

You are sending everyone off the page so, why bother?

Philip M
08-30-2008, 08:50 AM
This is a bug in IE. You need to create a slight delay before the function runs using setTimeout() (which is effectively what the alert is doing).

But as rubenbuhr says, what is the point as the user is leaving trhe page?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum