Click to See Complete Forum and Search --> : Please help with NEXT/PREVIOUS buttons


NooBee
06-13-2003, 09:42 AM
Hello all, I'm very new at this but I'm hoping you can help.
I'm not a programmer but I've set up a site for my cartoons.
Basically I have this Java double combo box set up for the archive section. From the first combo box, the user can select a range of strips to be viewed 1-30, 30-60 etc. From the, then propogated second list, the user can select a specific strip.
This works fine.
I've now written some code (untested) on the end of this, that calculates the 'next' strip and the 'previous' strip.
My problem is, I don't know how to insert buttons to make said functions work!
I'd like the user to be able to press either button and be zipped to the strip of their choice.
If the combo's could be updated to show the choice, that would be cool too. Please have a look over at:

The web site (http://theamoeba.ontheweb.com/)

and select the 'Archive' item in the menu at the top of the screen to see what I mean.
Many thanks in advance for anyone kind enough to help.
The code is as follows.......


<form name="doublecombo">
<p><select name="example" size="1" onChange="redirect(this.options.selectedIndex)">
<option>Strips 1-30</option>
<option>Strips 31-60</option>
<option>Strips 61-90</option>
<option>Strips 91-120</option>
</select>

<select name="stage2" size="1">
<option value="AmoebaStrips/Strip0000.gif">Strip 1</option>
<option value="AmoebaStrips/Strip0001.gif">Strip 2</option>
<option value="AmoebaStrips/Strip0002.gif">Strip 3</option>

(etc......)

</select>
<input type="button" name="test" value="Go!"
onClick="go()">
</p>

<script>
var groups=document.doublecombo.example.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group=new Array()

group[0][0]=new Option("Strip 1","AmoebaStrips/Strip0000.gif")
group[0][1]=new Option("Strip 2","AmoebaStrips/Strip0001.gif")

(etc.....)

group[1][0]=new Option("Strip 31","AmoebaStrips/Strip0030.gif")
group[1][1]=new Option("Strip 32","AmoebaStrips/Strip0031.gif")

(etc....)

group[2][0]=new Option("Strip 61","AmoebaStrips/Strip0059.gif")
group[2][1]=new Option("Strip 62","AmoebaStrips/Strip0060.gif")

(etc...)

group[3][0]=new Option("Strip 91","AmoebaStrips/Strip0089.gif")
group[3][1]=new Option("Strip 92","AmoebaStrips/Strip0090.gif")

(etc...)

var temp=document.doublecombo.stage2
function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options=new Option(group[x].text,group[x].value)

}

temp.options[0].selected=true

}

function go(){
top.frames["mainFrame"].location=temp.options[temp.selectedIndex].value

}

function getCurrentComicNum(selectEl) {
var selected = selectEl.options[selectEl.selectedIndex].text;
var currentNum = selected.substr(selected.indexOf("/"),selected.indexOf("."));
return parseInt(selected.replace(/^0-9/gi,""));
}

var baseURL = "AmoebaStrips/Strip";
var fileType = ".gif";
function nextComic(selectEl) {
var thisComic = getCurrentComicNum(selectEl);
thisComic++;
thisComic.toString();
while (thisComic.length<3) { thisComic = "0"+thisComic; }
top.frames["mainFrame"].location = baseURL + thisComic + fileType;
}
function prevComic(selectEl) {
var thisComic = getCurrentComicNum(selectEl);
thisComic--;
thisComic.toString();
while (thisComic.length<3) { thisComic = "0"+thisComic; }
top.frames["mainFrame"].location = baseURL + thisComic + fileType;
}

//-->
</script>
http://theamoeba.ontheweb.com http://theamoeba.ontheweb.com My web site (http://theamoeba.ontheweb.com)

Khalid Ali
06-13-2003, 10:39 AM
Originally posted by NooBee

...........
My problem is, I don't know how to insert buttons to make said functions work!
........

By looking at your site,its not clear how you are planning to implement the question.
You have the selections boxes appear in a popup window..do you want to have buttons underneath those selection boxes in the popup????

Khalid Ali
06-13-2003, 11:06 AM
More problems when I was looking at your code...
in the function getCurrentComicNum(selectEl)

there are several problems in here...

I am guessing you want to strip the number from the strip name

such as

Strip 2

should be returned as 2??????

NooBee
06-13-2003, 11:07 AM
Yeah, that's what I was hoping for.
There's a GO button in there already so either side of that.
The user would then be able to either, select a strip from the pull down menu and hit Go, or just hit 'next' (or indeed previous).
I was attempting to re-proporgate the menus too.
This only came about because visitors to the site complained about having to re-select a strip from the lists.
Hoping you, and others can help me out.
Cheers.
NooBee.... Paul

NooBee
06-13-2003, 11:15 AM
Originally posted by Khalid Ali
I am guessing you want to strip the number from the strip name

such as

Strip 2

should be returned as 2??????

Yeah. This was where I realised I was in above my head. That script I wrote could well be rubbish! I was trying to get a handle on a reference, something numerical that the strip could be referred to as (that probably makes no sense).

In the menu code, the strips already have names for the 'loading of', I should really just stick to using those as I can see all kinds of problems arising.

Would you recommend scrapping that piece of coding then?

Cheers again.
Fast feedback too, very much appreciated. :)

Khalid Ali
06-13-2003, 11:30 AM
In that case add the following in the html section just below the "Go" button


<br/>
<input type="button" value="Previous" onclick="prevComic(document.doublecombo.stage2)"/>&nbsp;&nbsp;<input type="button" value=" Next " onclick="nextComic(document.doublecombo.stage2)"/>


Then replace the
getCurrentComicNum(selectEl)

function with this one

function getCurrentComicNum(selectEl) {
var selected = selectEl.options[selectEl.selectedIndex].text;
var currentNum = selected.substring(selected.indexOf("Strip")+5,selected.length);
return parseInt(currentNum);
}


now if the rest (I mean targetting of the next/prev resource) is correct then you should be fine..

else post the error that you may recieve

NooBee
06-13-2003, 12:38 PM
Oooooh so close.
May I say, thank you VERY much for the attention you've shown this so far.

It works to a certain extent but for just one minor flaw.

I saw that the buttons work brilliantly but when clicked, the strip to load isn't found.
As you will no doubt have predicted, the fact that the code adds or subtracts 1 from the current loaded strip and appends it to the end of the string to load, it misses out the 0's that proceed the strip name.

Eg, it tries to load Strip2.gif instead of Strip0002.gif

Now, two ways can be gone with this. Find some cunning way of getting round it by adding 0's to the string. 3 for numbers less than 10. 2 for numbers less than 100 and 1 for...
you get it. Or, I could go in and re-name all the 102 strips I have so far, stripping them of their 0's.

What do you think?

Again, thank you very much for your help.
NooBee, Paul.

Khalid Ali
06-13-2003, 02:37 PM
In that case here you go..

function getCurrentComicNum(selectEl) {
var selected = selectEl.options[selectEl.selectedIndex].value;
var currentNum = selected.substr(selected.indexOf("/"),selected.indexOf("."));
return parseInt(selected.replace(/^0-9/gi,""));
}

NooBee
06-13-2003, 04:45 PM
Very bizarre.
Balancing on the edge of excellence.
But for nearly the same problem again.
Sorry about this.
Now, when the Next is clicked it tries to load StripNaN.gif
:confused:
Cheers.
Paul.
(NooBee)

Khalid Ali
06-13-2003, 05:40 PM
Hellow Paul,
replace the infamous getCurrentComicNum(selectEl)

with this (3 functions altogether)

function getCurrentComicNum(selectEl) {
var selected = selectEl.options[selectEl.selectedIndex].value;
var currentNum = selected.substring(selected.indexOf("/Strip")+6,selected.indexOf("."));
var temp = stripZeros(currentNum);
return new Array(temp[0],temp[1]);
}

function stripZeros(currentNum){
var ctr=0;
for(var x=0;x<currentNum.length-1;x++){
if(currentNum.charAt(x)=="0"){
ctr++;
}
}
ctr = (Number(currentNum)==9)?ctr-1:ctr;
return new Array(Number(currentNum),ctr)
}

function createURL(path,flag,len){
var str="";
for(var x=0;x<len;x++){
str+="0"
}
return flag+str+path;
}

NooBee
06-13-2003, 05:59 PM
This is getting very complicated now. I'm having trouble keeping up.
I'm sorry to say, it's still the same.
Still trying to load StripNaN.gif
Don't know what you just wrote but your previous coding probably wasn't to blame, but mine.

Check out the URL I posted earlier as I've put it online.

Many thanks again.
Paul,
NooBee.

NooBee
06-13-2003, 06:03 PM
Better still than the last URL,
Maybe you should try...

http://mysite.freeserve.com/theamoeba/StripPageWindow.htm

As then you don't get the annoying popup window when de-bugging.

Cheers.
Paul.

Khalid Ali
06-13-2003, 06:21 PM
The problem is that I am trying to work with your logic...and I am not completely awae of that...if I had to do it myself..it would have been done long ago...I'll take a look at all that now..

Khalid Ali
06-13-2003, 06:52 PM
Ok check this out...it solves the problem ...though there are more issues to be taken care of..

http://68.145.35.86/temp/NooBee/frames.html

NooBee
06-14-2003, 05:06 PM
I'm sorry for the slow reply, I didn't realise you'd added anything as I didn't get an e-mail update.
Well, it's looking good so far, but I agree with having more issues. Do you think if I'd stuck with your original suggestion and changed the strip names, omitting the additional 0's that all this would have been such a problem?
I see, with the new code, that it does indeed load the next strip, but doesn't load any others, ie if you press 'next' after a 'next' it won't work. It only does one forward or backward.

By the way, what is the 'process' box that I get?

Cheers again for your time.
Paul.

Khalid Ali
06-14-2003, 09:13 PM
Yes I new that..its because get current numnber is not being changed in the select boxes...I'll be able to work on it with you on monday....If you'd like..:D

NooBee
06-15-2003, 06:21 AM
That would be excellent.
Thanks again. :D
I'm going through the code you post, so I'm learning.... slowly.
Cheers.
Paul.
PS, I think your hard work deserves a speacial thanks onsite, unless you'd rather not.

NooBee
06-18-2003, 05:25 PM
Hope this reminder works as requested.
Cheers.
Paul (NooBee)

Khalid Ali
06-18-2003, 06:42 PM
Hello Paul,
I was able to spend some time(actually had to do some thing too) on it,take a look at the link below.

http://68.145.35.86/temp/NooBee/frames.html

NooBee
06-19-2003, 06:54 AM
Khalid.
That link you posted me doesn't work!!! I get a gateway error. I've tried a few times but no joy.
Cheers.
Paul. NooBee.

Khalid Ali
06-19-2003, 08:51 AM
It doesn't make sense..can you please post the full error,cus I don't see any problems with it ,I just tested it again..

NooBee
06-19-2003, 09:46 AM
YEAH!!!!!
It works.
I really don't know why it wouldn't work before, and the several times I tried previous to that.
All I got was a complete seize of the PC and a Gateway error.
Now it's fine and dandy.
Many thanks.
I'm not worthy....
Cheers.
Paul.

Khalid Ali
06-19-2003, 09:50 AM
You are welcome Paul..have a good one.

NooBee
07-04-2003, 04:27 PM
I'm terribly sorry to drag this up again.
You recall the above script you wrote and the problem with the NEXT/PREVIOUS buttons?
Well, I've hit a problem.
Everything was great until I passged the 100 mark and now the code adds one too many 0's the the next strip to load!
So, it tries to load 00101 instead of 0101.
I've tried changing the file names, but that didn't work too well.
The code you wrote is still at
The same site (http://mysite.freeserve.com/theamoeba/StripPageWindow.htm)
Hope you can help again.
Thanks for your time.
Paul.

NooBee
07-10-2003, 03:57 PM
Anybody?
:(
The code I have so far is SO near perfect, it's a shame to leave it that way.
Paul.

Khalid Ali
07-10-2003, 05:03 PM
Hey paul ..sorry I missed your post some wehre....don't despair..I think I still have the pages on my machine some where,Ill see if they are I'll fix the bug and let ya know in couple of days..

NooBee
07-10-2003, 05:11 PM
Thanks a million.
Very much appreciated.
Paul.

Khalid Ali
07-11-2003, 11:18 PM
Take a looksy paul..same link...:D

NooBee
07-12-2003, 02:15 PM
Wow, you're very good.
I've taken a while to answer your post cos the link to your pages made my PC freeze!
It works 100% perfect now and I am eternally endebted.
I can't thank you enough for all the hard work you've put into this script.
Cheers.
Paul.

Khalid Ali
07-12-2003, 03:10 PM
you are welcome
:D