Javascript question

NO SPAM ALLOWED! Discuss stuff not related to Japan or Japanese. The rules are the same in this forum as in the other forums.
Post Reply
ashitaka
Posts: 456
Joined: Sun 10.30.2005 1:08 pm

Javascript question

Post by ashitaka » Tue 02.13.2007 6:54 pm

From a while back there was a thread about CSS or something and i noticed a whole bunch of other coders where useing TJP.
Anyways I'm helping with the schools newspaper site and now I'm making a photo-essay thing with javascript, but I have forgoten practically everything about JS.

The problem with this code is it doesn't show the pictures, which is the whole point of a photo essay, however the descriptions show fine.

This is just the script the part,
<script type="text/JavaScript">
<!--

var slide_num=new Array(slide_num)
for (i=0; i <slide_num; i++)
slide_num[i]=new Array()

// insert link for corresponding slide. //creat more thingies bellow for each picture on the slideshow thingy
// must have at least 5 slides
slide_num[1]='http://www.eblong.com/zarf/uncarrot/picfull/blank.jpeg'
slide_num[2]='http://www.toothpastefordinner.com/050603/nothing-more-reassuring.gif'
slide_num[3]='http://www.toothpastefordinner.com/051706/a-s-l.gif'
slide_num[4]='http://www.toothpastefordinner.com/051506/web-cartoonists-do-it-once-a-day-at-midnight.gif'
slide_num[5]='http://www.toothpastefordinner.com/051406/senior-comparatives.gif'
{


num_of_slides = 5; // this number must correspond to the number of slides above
slide_num = 1; // the slide the thingymajig starts on
//text that goes with each picture // add more to equal number of slides
desc1 = "Description in here"
desc2 = "Description in here"
desc3 = "Description in here"
desc4 = "Description in here"
desc5 = "Description in here"
}

// Don't touch these!
function firstslide(){
slide_num = 1;
changeslide();
}
function prevslide(){
slide_num = slide_num - 1;
if(slide_num < 1){
slide_num = num_of_slides;
}
changeslide();
}
function nextslide(){
slide_num = slide_num + 1;
if(slide_num > num_of_slides){
slide_num = 1
}
changeslide();
}
function lastslide(){
slide_num = 5; // Must correspond to the # of total slides.
changeslide();
}


// This function changes the slide and the description box according to the slide_num
function changeslide(){

// Changes the slide
eval('document.picbox.src = "' + slide_num + '"');

// Changes the description box
eval('document.descform.descbox.value = "Slide ' + slide_num + ': ' + eval('desc' + slide_num) + '"');
}
// end hiding contents -->
</script>


Here is the rest but this should work fine.
</head>
<body bgcolor="#a80000" onload="changeslide()">
<div align="center">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<center><h3>TITLE</h3></center> <!-- Use PhP to insert title -->
</td>
</tr>
<tr >
<td height="2"></td>
</tr>
<tr> <!-- the src bellow must be the same as the first picture of the slide. -->
<td><img id="image" src="http://www.eblong.com/zarf/uncarrot/picfull/blank.jpeg" alt="Image 400x300" name="picbox" height="300" width="400" /></td>
</tr>
<tr>
<td>
<table class="cellcolor" width="400" border="0" cellspacing="0" cellpadding="0" bgcolor="#a80000">
<tr>
<td align="center" valign="middle" width="100"><a href="javascript:firstslide()">First</a></td>
<td align="center" valign="middle" width="100"><a href="javascript:prevslide()">Prev</a></td>
<td align="center" valign="middle" width="100"><a href="javascript:nextslide()">Next</a></td>
<td align="center" valign="middle" width="100"><a href="javascript:lastslide()">Last</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="5"></td>
</tr>
<tr>
<td>
<form name="descform">
<textarea name="descbox" rows="3" cols="46" onFocus="this.blur()">
</textarea>
</form>
</td>
</tr>
</table>
<p></p>
</div>
</body>
</html>

Thanks in advance, :D
Last edited by ashitaka on Tue 02.13.2007 6:55 pm, edited 1 time in total.

User avatar
chikara
Posts: 3577
Joined: Tue 07.11.2006 10:48 pm
Native language: English (Australian)
Gender: Male
Location: Australia (SA)
Contact:

RE: Javascript question

Post by chikara » Tue 02.13.2007 7:40 pm

I've only had time for a quick look but for starters I am confused as to what data type slide_num is. It is declared as both an array and an array index.

<script type="text/JavaScript">
<!--

var slide_num=new Array(slide_num)
for (i=0; i <slide_num; i++)
slide_num[i]=new Array()

// insert link for corresponding slide. //creat more thingies bellow for each picture on the slideshow thingy
// must have at least 5 slides
slide_num[1]='http://www.eblong.com/zarf/uncarrot/picfull/blank.jpeg'
slide_num[2]='http://www.toothpastefordinner.com/050603/nothing-more-reassuring.gif'
slide_num[3]='http://www.toothpastefordinner.com/051706/a-s-l.gif'
slide_num[4]='http://www.toothpastefordinner.com/051506/web-cartoonists-do-it-once-a-day-at-midnight.gif'
slide_num[5]='http://www.toothpastefordinner.com/051406/senior-comparatives.gif'


I changed the above to;

<script type="text/JavaScript">
<!--

var aSlide_num=new Array(5)
// comment this out as not sure why we need a multi-dimensional array here
//for (i=0; i <slide_num; i++)
//slide_num[i]=new Array()

// insert link for corresponding slide. //creat more thingies bellow for each picture on the slideshow thingy
// must have at least 5 slides
aSlide_num[1]='http://www.eblong.com/zarf/uncarrot/picfull/blank.jpeg'
aSlide_num[2]='http://www.toothpastefordinner.com/050603/nothing-more-reassuring.gif'
aSlide_num[3]='http://www.toothpastefordinner.com/051706/a-s-l.gif'
aSlide_num[4]='http://www.toothpastefordinner.com/051506/web-cartoonists-do-it-once-a-day-at-midnight.gif'
aSlide_num[5]='http://www.toothpastefordinner.com/051406/senior-comparatives.gif'


and then this code;

// Changes the slide
eval('document.picbox.src = "' + slide_num + '"');


becomes;

// Changes the slide
eval('document.picbox.src = "' + aSlide_num[slide_num] + '"');


and that seems to work to a point.

Hope that helps.
Don't complain to me that people kick you when you're down. It's your own fault for lying there

ashitaka
Posts: 456
Joined: Sun 10.30.2005 1:08 pm

RE: Javascript question

Post by ashitaka » Tue 02.13.2007 9:27 pm

Oh great Chikara, god of Javascript, praise be to you who hath helped a poor soul in search of answers.

// comment this out as not sure why we need a multi-dimensional array here
//for (i=0; i <slide_num; i++)
//slide_num[i]=new Array()

I was taking that out, never did understand it myself
var aSlide_num=new Array(5)

*bangs head on wall* stuiped stuiped stuiped!
Thank you for saving me from days of pain and torture.

P.S. those pictures were just an empty refrence.

*goes back to HTML*

User avatar
chikara
Posts: 3577
Joined: Tue 07.11.2006 10:48 pm
Native language: English (Australian)
Gender: Male
Location: Australia (SA)
Contact:

RE: Javascript question

Post by chikara » Tue 02.13.2007 9:45 pm

ashitaka wrote:
Oh great Chikara, god of Javascript, praise be to you who hath helped a poor soul in search of answers.....

どういたしまして。
よろしく、
ジャワスクリプトの神  :D
Don't complain to me that people kick you when you're down. It's your own fault for lying there

Post Reply