Support Forums

Full Version: Javascript Help =(Has some PHP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Im making a gallery in javascript, and it uses a PHP script to make a javascript array out of all the pictures in /images. the only problem is on my button for next() doesnt load anything in the page, but if i look at the pages source it SHOULD work
i have not a clue what the problem is, below is the source of the php file, and then the output of my next() function, the problem has to be within the next() output but i cant for hte life of me see what it is.

if you want to go look first hand at the problem you can go to
http://animenerds.biz/
click Next 20, and the page will come up blank, if you right click and select THis Frame -> View FRame SOurce you will see the next() output.

here is the source:
Code:
<?php
$dir = opendir("images");
$num = 0;
echo("<html><head><script type='text/javascript'> var images=new Array();");
while (($file = readdir($dir)) !== false)
  {
  if (eregi("(\.png$)|(\.jpg$)|(\.gif$)|(\.jpeg$)", $file)) {
    echo("images[" . $num . "] = '" . $file . "';");
    $num++;
    }
  }
closedir($dir);
?>
<!-- hide
var sBeg = 20;
var sEnd = 40;
function scale() {
for (a=0;a<=document.getElementsByTagName('img').length;a++)
{
x=document.getElementsByTagName('img')[a];
x.width = x.width*100/x.height;
x.height = 100;
if (x.width>250) {
x.width = 200
}
}
}
function makeURL(a)
{
  return('<a href="http://animenerds.biz/images/'+images[a]+'"><img src="http://animenerds.biz/images/'+images[a]+'" />')
}
function insRow(sb,se)
{
    var pos = 0;
    var rw = 0;
    x = document.getElementsByTagName('table')[0].insertRow(rw);
    var images2 = images.slice();
    images2 = images2.slice(sb,se);
    for (Image in images2)
    {
        s = x.insertCell(pos);
        s.innerHTML = makeURL(pos+(se-20)+(rw*5));
        if (pos == 4)
        {
            rw = rw + 1;
            x = document.getElementsByTagName('table')[0].insertRow(rw);
            pos = 0;
            continue;
        }
        pos = pos + 1;
    }
    scale();
    document.close();
}
function next()
{
var sbeg = sBeg+20;
var send = sEnd+20;
document.write("<html><head><script type='text/javascript' src='http://animenerds.biz/bla.js'></script><script type='text/javascript'>var sBeg = "+sbeg+";var sEnd = "+send+";");
for (b in images)
{
document.write('var images['+b+'] = '+images[b]+';');
}
document.write("</script><link rel='stylesheet' type='text/css' href='http://animenerds.biz/style.css' /></head><body onload='insRow("+sBeg+","+sEnd+")'><input type='button' value='Next 20' onclick='next()' /><table></table></body></html>");
document.close()
}
// -->
</script><link rel="stylesheet" type="text/css" href="http://animenerds.biz/style.css" /></head>
<body onload="insRow(0,20)"><input type='button' value='Next 20' onclick='next()' />
<table>
</table>
<br />

</body>
</html>


here is the output of my next() function: all of it looks like it should work, but of course it wont ^^
Code:
<html><head><script type='text/javascript' src='http://animenerds.biz/bla.js'></script><script type='text/javascript'>var sBeg = 40;var sEnd = 60;var images=new Array();var images[0] = 11klgys.jpg;var images[1] = 1242893883645.png;var images[2] = 1248376027185.png;var images[3] = 1249607129448.png;var images[4] = 1258781563531.png;var images[5] = 1258786950787.jpg;var images[6] = 1iiejl2.png;var images[7] = 25thun5.png;var images[8] = 2eb5x0h.jpg;var images[9] = 2mg7cjp.png;var images[10] = 6572_1226208337698_1303731779_647769_4811004_n.jpg;var images[11] = 77356784.jpg;var images[12] = 1.png;var images[13] = 1240773749891.jpg;var images[14] = 1249402652580.jpg;var images[15] = 1249605096549.png;var images[16] = 1249859730619.jpg;var images[17] = 1250146281734.jpg;var images[18] = 1255385221043.jpg;var images[19] = 1256924619830.jpg;var images[20] = 1258143943448.jpg;var images[21] = 1218563822760.jpg;var images[22] = 033ca85a.png;var images[23] = 0420b6cb.png;var images[24] = 05199832.png;var images[25] = 06804697.png;var images[26] = 08d6ca54.png;var images[27] = 0fa5cae0.png;var images[28] = 0fd90942.png;var images[29] = 1141324731.png;var images[30] = 1165771455fs6.png;var images[31] = 11ba2512.png;var images[32] = 1218487701668.png;var images[33] = 1218522548523.gif;var images[34] = 1218565670035.jpg;var images[35] = 1219525436449.png;var images[36] = 1220675493135.png;var images[37] = 1223168365390.png;var images[38] = 125b094d.png;var images[39] = 18b953b0.png;var images[40] = 1d0f842c.png;var images[41] = 20cc1cf8.png;var images[42] = 220e8fd3.png;var images[43] = 225fb9fd.png;var images[44] = 24REI0.png;var images[45] = 2d0cdd48.png;var images[46] = 3a391f20.png;var images[47] = 417110bf1.jpg;var images[48] = 4356336d.png;var images[49] = 43d19e19.png;var images[50] = 4b5436f2.png;var images[51] = 4c31f09f.png;var images[52] = 4chrm1g.png;var images[53] = 4f20730b.png;var images[54] = 4thhokagecopy.png;var images[55] = 54a47ea7.png;var images[56] = 5bg3873.png;var images[57] = 5d159c49.png;var images[58] = 5e67dab1.png;var images[59] = 646eaefd.png;var images[60] = 669fb9f3.png;var images[61] = 677f2840.png;var images[62] = 69dbb13e.png;var images[63] = 6thSquadRender.png;var images[64] = 7367de9f.png;var images[65] = 7c9b90cc975a1985fb1133ecu6.png;var images[66] = 7d447b66.png;var images[67] = 81605084.png;var images[68] = 8237149a.png;var images[69] = 84997e25.png;var images[70] = 8756yoko-render.png;var images[71] = 8d3c4ff0.png;var images[72] = 8edf9469.png;var images[73] = 92d088e2.png;var images[74] = 997917b1.png;var images[75] = 9a438959.png;var images[76] = 9ec69855.png;</script><link rel='stylesheet' type='text/css' href='http://animenerds.biz/style.css' /></head><body onload='insRow(20,40)'><input type='button' value='Next 20' onclick='next()' /><table></table></body></html>
Ah no nvm.
(11-28-2009, 02:08 AM)Xenocide Wrote: [ -> ]
Code:
<script type='text/javascript'
You forgot to close it with ">" It's in the first line.

no i didnt, it uses an external JS script for the first script element
<script type='text/javascript' src='http://animenerds.biz/bla.js'>
Yeah just noticed.
Did you fix this because it's apparently working for me in Opera?

EDIT: Tested in IE8 and it's not working but it is in Firefox 3.5.5.

Do you have the javascript compressed? Your syntax looks screwey. Why is "<!-- hide" at the end of the first line? That should be right after the script tag not after the var.

Also you have no doctype or charset. This could be causing browser problems. Start with fixing syntax and it might fix the problem or at least make it more obvious. Make it a habit to validate your xhtml.
(11-29-2009, 01:58 AM)Omniscient Wrote: [ -> ]Did you fix this because it's apparently working for me in Opera?

EDIT: Tested in IE8 and it's not working but it is in Firefox 3.5.5.

Do you have the javascript compressed? Your syntax looks screwey. Why is "<!-- hide" at the end of the first line? That should be right after the script tag not after the var.

Also you have no doctype or charset. This could be causing browser problems. Start with fixing syntax and it might fix the problem or at least make it more obvious. Make it a habit to validate your xhtml.

yea so far it works in Firefox, right now I havent started adding exceptions for certain browsers. I wish every browser had the javascript functionality of Firefox =(. The only problem now is when I click Next 20 before the pictures load, the next page wont load anything and i have to refresh the frame. Thats probably a problem with my body onload= or something. And thanks for the tips ^__^
You should take a look at the Image preloading stuff.
http://articles.techrepublic.com.com/510...14317.html

You can preload them to solve the refresh problem....
(11-29-2009, 09:42 AM)Master of The Universe Wrote: [ -> ]You should take a look at the Image preloading stuff.
http://articles.techrepublic.com.com/510...14317.html

You can preload them to solve the refresh problem....

thanks for this =) reading now.
Realistically javascript makes a poor choice for gallery scripting. You should do this in straight php and get rid of the frames. The script isn't very good. You can do this easily enough with php.
(11-29-2009, 12:19 PM)Omniscient Wrote: [ -> ]Realistically javascript makes a poor choice for gallery scripting. You should do this in straight php and get rid of the frames. The script isn't very good. You can do this easily enough with php.

yea i know i could do it all in PHP hehe but im just practicing javascript for now, on w3schools it says i cant learn PHP until i finish the javascript part so I thought this would be perfect practice since I like pictures in all ^__^. Once I start PHP i'll try and recode it all in PHP.
Pages: 1 2