Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

php + javascript help

Name: confused 2009-01-07 2:31

hey /g/ i have a question about web coding.
im using php and javascript to output a grid of thumbnails which when clicked upon will load a larger version of the image in another part of the page. the thumbnail load, i can get an image to change, but for some reason the thumbnails wont load the larger image. here's the code i have:

<SCRIPT LANGUAGE ="JavaScript">
function clicky(f)
{
active.src=("images/environments/"+f);
}
</SCRIPT>

<?php
$i=0;
$filenames=scandir("images/environments");//puts filenames into an array
foreach($filenames as $file)//somehow goes through the array and...
{
if(!($file == '.' or $file == '..'))
{
if($i==2)
{
echo '<br>';
$i=0;
}
echo '<img src="images/thumbs/t'.$file.'" onclick="clicky('.$file.')">';
$i++;
}
}
?>

and later in the page, the large image that should change:

<img name="active" src ="images/environments/Giraffetapus.jpg">

any idea what the heck is wrong with it?
basically, im tying to figure out why, when i click on the thumbnails, the image dosent change. i think its in either the cilcky() function or the onclick event

Name: confused 2009-01-07 2:42

well i kind of tried that, but i just put "this.src=new_filename" into a function and used php for the "new_filename" part.

it just dosent seem to be working.

Name: confused 2009-01-07 2:47

>>4
you got it:

<img src="images/thumbs/tGiraffetapus.jpg" onclick="clicky(Giraffetapus.jpg)"><img src="images/thumbs/tIMASHARKKKK.jpg" onclick="clicky(IMASHARKKKK.jpg)"><br><img src="images/thumbs/tLoveMeSomeCurlyBrace.jpg" onclick="clicky(LoveMeSomeCurlyBrace.jpg)"><img src="images/thumbs/tME.jpg" onclick="clicky(ME.jpg)"><br><img src="images/thumbs/tdress.gif" onclick="clicky(dress.gif)"><img src="images/thumbs/tdyke.jpg" onclick="clicky(dyke.jpg)"><br><img src="images/thumbs/teyegunk.jpg" onclick="clicky(eyegunk.jpg)"><img src="images/thumbs/tfighting spirit.jpg" onclick="clicky(fighting spirit.jpg)"><br><img src="images/thumbs/tgirl.jpg" onclick="clicky(girl.jpg)"><img src="images/thumbs/thack.jpg" onclick="clicky(hack.jpg)"><br><img src="images/thumbs/tike.jpg" onclick="clicky(ike.jpg)"><img src="images/thumbs/tjohnnyandplank.jpg" onclick="clicky(johnnyandplank.jpg)"><br><img src="images/thumbs/tkayla.jpg" onclick="clicky(kayla.jpg)"><img src="images/thumbs/tlyle.jpg" onclick="clicky(lyle.jpg)"><br><img src="images/thumbs/tsuicide.jpg" onclick="clicky(suicide.jpg)"><img src="images/thumbs/ttekkon.jpg" onclick="clicky(tekkon.jpg)"><br><img src="images/thumbs/ttubegun.jpg" onclick="clicky(tubegun.jpg)">

Name: Anonymous 2009-01-07 2:59

>>7
ok let me see if i can use that. thanks!

Name: Anonymous 2009-01-07 3:23

>>9
I guess I'm not getting it. I used:

<img name="active" src ="images/environments/Giraffetapus.jpg">

as my index image. i also tried just substituting your clicky function for mine, but i got the same result.

Name: Anonymous 2009-01-07 3:29

holys shit! i got it. thanks so much for the help!

i was missing the quotes aroumnd the filename in the call to clicky

Name: Anonymous 2009-01-07 4:14

What fucking year is this. Is it 1998? Why the fuck do you have code in your markup. And why is that code directly echoing static markup directly to the page.

And what is with that markup. It must be 98. Your line break and image elements are poorly formed.

Name: FrozenVoid!FrOzEn2BUo 2009-01-07 4:17

>>14
first of all, it's 2009 in case you didn't notice.
Next, inlining code fragments in html is actually a well established web development best practice.
I might suggest you go back to your toy haskell language, and let us real programmers with jobs do the real work, kiddo.

Don't change these.
Name: Email:
Entire Thread Thread List