rudy507 Posted February 13, 2007 Share Posted February 13, 2007 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 https://forums.phpfreaks.com/topic/38371-onclick-event-problems/ Share on other sites More sharing options...
fenway Posted February 13, 2007 Share Posted February 13, 2007 I'm not sure how you think your onlick assignment will work -- you're not actually using the variable values. Link to comment https://forums.phpfreaks.com/topic/38371-onclick-event-problems/#findComment-184042 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.