Jump to content

onClick event problems


rudy507

Recommended Posts

Hey guys,

I've got some javascript code that I am using to hide & display divs. Ok, first off: The first div is not being displayed at all. When you click next, the 2nd div is being displayed. However, the "next" button also disappears. Any ideas why?

 

The Javascript Functions:

<script type="text/javascript">
function display_div(id) {
var div = id;
var srcElement = document.getElementById(div);
srcElement.style.display = "block"; 
}
function hide_div(id) {
var div = id;
var srcElement = document.getElementById(div);
srcElement.style.display = "none"; 
}
<!-- The next function is used in photo_gallery.php -->
function next_photo_gallery(current_id, next_id, array_length) {
var current_div = current_id;
var this_div = next_id;
var on_deck_div = new Number(array_length - this_div + 1);
var srcElement = document.getElementById('next_photo_button');
var length = array_length;

if (on_deck_div > length) {
	on_deck_div = '0';
}

hide_div(current_div);
display_div(this_div);

srcElement.onClick = "next_photo_gallery(this_div, on_deck_div, array_length)";
}
</script>

 

The PHP & Javascript being used to output the Divs, etc...:

// Set the Directory Location
$directory = opendir('../premier_images/');

// Put every picture in the directory into an array
echo "<div><script type=\"text/javascript\">
	var output = new Array()
	var i = 0;
";
while ($picture = readdir($directory)) {
if ($picture != "." && $picture != "..") {
// Testing Purposes
	// echo "</script>$picture <br /><script type=\"text/javascript\">";
// End Testing
echo "\toutput[i] = '$picture'\n"
            ."\tif (i > 0) {"
            ." document.write("
            	."'<div id='+output[i]+' style=\"align=\'center\';valign=\'center\';display:none;\">"
            	."<img src=\"../premier_images/'+output[i]+'\">"
            	."<br />"
            	."</div>');"
            ." }\n"
            ."\ti++;\n";
}
}
echo "\tdocument.write("
."'</div><div id='+output[0]+' style=\"align=\'center\';valign=\'center\';\">"
."<br /><br />"
."<input id=\'next_photo_button\' type=\'button\' value=\'Next Photo\' onClick=\"next_photo_gallery(output[0], output[1], output.length)\">"
."');\n"
."\t</script>\n";
?>

 

Thanks for any help,

David

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.