1.

Solve : javascript help :)?

Answer»

hi guys how would i go about doing this for a script:

i have a webpage with 3 buttons: start, next and previous

now i have 1 set of pages NAMED:

page1.html
page2.html
page3.html

("page" will be different when it is actually made though

when i am on page1 the previous and the start buttons src will be "images/Blue_CSS/button_side_off" but the next button src will be "images/Blue_CSS/button_side_next"
when this is clicked from page1 it wqill TAKE you to page2, and if you werte on page2 it would then take you to page3 ect.

same with the previous button but the numbers go down instead and the start button brings you back to page1

any ideas how i would extrtact the number in the html and just add 1 or minus one?
ok here is my atempt... this is probably very messy but it works

could anyone see if they can find any problems or ways of making it better please

Code: [Select]var href = window.location.href+"  ";
var nobutton = "<img src=\"../images/Blue_CSS/side_button_off.png\" />";
var link1 = "<a href=\""
var link2 = "\"><img src=\"../images/Blue_CSS/side_button_"
var link3 = ".png\" /></a>"

var name = "Steven COLLINS"
var candnum = "9026"
var centernum = "52137"
var cand = "Candidate name</br>"
var cand1 = "Candidate number</br>"
var cent = "Centre number</br>"


// page number selection :)

if (href.search('-1')>0){pagenum='1'; nextpagenum='2'; previouspagenum='0'}
if (href.search('-2')>0){pagenum='2'; nextpagenum='3'; previouspagenum='1'}
if (href.search('-3')>0){pagenum='3'; nextpagenum='4'; previouspagenum='2'}
if (href.search('-4')>0){pagenum='4'; nextpagenum='5'; previouspagenum='3'}
if (href.search('-5')>0){pagenum='5'; nextpagenum='6'; previouspagenum='4'}
if (href.search('-6')>0){pagenum='6'; nextpagenum='7'; previouspagenum='5'}
if (href.search('-7')>0){pagenum='7'; nextpagenum='8'; previouspagenum='6'}
if (href.search('-8')>0){pagenum='8'; nextpagenum='9'; previouspagenum='7'}
if (href.search('-9')>0){pagenum='9'; nextpagenum='10'; previouspagenum='8'}
if (href.search('-10')>0){pagenum='10'; nextpagenum='0'; previouspagenum='9'}

//page selection

if (href.search('9onlines')>0)
{
pagename='9onlines';
lastpagenum='3';
chapter='1';
}
else if (href.search('ebook')>0)
{
pagename='selection';
}
else if (href.search('index')>0)
{
pagename='index';
}
else if (href.search('chapter')>0)
{
pagename='chapter';
chapter=pagenum;
}
else
{
pagename='none';
}

document.getElementById("candname").innerHTML=cand + name;
document.getElementById("candnum").innerHTML=cand1 + candnum;
document.getElementById("centnum").innerHTML=cent + centernum;

// everything else

if (!(pagename=='none') && !(pagename=='chapter') && !(pagename=='selection') && !(pagename=='index'))
{
if (pagenum=='1')
{
document.getElementById("start_button").innerHTML=link1 + "chapter-" + chapter + ".html" + link2 + "back" + link3;
}
else
{
document.getElementById("start_button").innerHTML=link1 + pagename + "-1.html" + link2 + "start" + link3;
}

if (pagenum==lastpagenum)
{
document.getElementById("next_button").innerHTML="<img src=\"../images/Blue_CSS/side_button_off.png\" />";
}
else
{
document.getElementById("next_button").innerHTML=link1 + pagename + "-" +  nextpagenum + ".html" + link2 + "next" + link3;
}

if (pagenum=='1')
{
document.getElementById("prev_button").innerHTML="<img src=\"../images/Blue_CSS/side_button_off.png\" />";
}
else
{
document.getElementById("prev_button").innerHTML=link1 + pagename + "-" +  previouspagenum + ".html" + link2 + "PREV" + link3;
}
}
else if (pagename=='selection')
{
document.getElementById("start_button").innerHTML=link1 + "chapter1/chapter-1.html" + link2 + "chapter-1" + link3;

document.getElementById("next_button").innerHTML=link1 + "chapter2/chapter-2.html" + link2 + "chapter-2" + link3;

document.getElementById("prev_button").innerHTML=link1 + "chapter3/chapter-3.html" + link2 + "chapter-3" + link3;
}
else if (pagename=='index')
{
document.getElementById("start_button").innerHTML="<img src=\"../images/Blue_CSS/side_button_off.png\" />";

document.getElementById("next_button").innerHTML="<img src=\"../images/Blue_CSS/side_button_off.png\" />";

document.getElementById("prev_button").innerHTML="<img src=\"../images/Blue_CSS/side_button_off.png\" />";
}
else if (pagename=='chapter')
{
document.getElementById("start_button").innerHTML=link1 + "../ebook.html" + link2 + "back" + link3;

document.getElementById("next_button").innerHTML="<img src=\"../images/Blue_CSS/side_button_off.png\" />";

document.getElementById("prev_button").innerHTML="<img src=\"../images/Blue_CSS/side_button_off.png\" />";
}



Discussion

No Comment Found