Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A problem with a function and link

Status
Not open for further replies.

johncalvin

Programmer
Oct 10, 2002
4
GB
i've been trying to make my life easy by working out if i can have a link in my html be in relation to a variabkle set in javascript.

In my script section i have

function nextch()
{
chapter=1;
forward=chapter+1;
first="ch_";
last=".htm";
destination=first+forward+last;
parent.mainFrame.location.href(destination);
}

and in the body of the html file i have this <a> tag wrapped around an image

<a href=&quot;#&quot; onClick=&quot;nextch()&quot; onmouseover=&quot;image3.src='onmouseout=&quot;image3.src='
If anyone can see glaringly obvious problems with this any help would be great.
 
Instead of this:
destination=first+forward+last;

do this:
destination = eval(first+forward+last);


And instead of this:
parent.mainFrame.location.href(destination);

do this:
parent.mainFrame.location.href = destination;
 
Cheers

Still having trouble though. I think it maybe the fact i am not calling the function correctly.

Does anyone know how i would be able to have the contents of the 'destination' variable as the value of the <a href> value.
 
Your nextch() function will never go past chapter 2 since you're always reseting the chapter to 1 when it's called. Move chapter=1 outside of the function like this:

chapter=1;
function nextch(){
parent.mainFrame.location.href=&quot;ch_&quot;+(++chapter)+&quot;.htm&quot;;
}

Don't use eval(), it's not necessary.
 
Cheers

as far as i understand i can't have a linked .js file and some seperate script inside the script tag. as i want the chapter variable to correspond with the chapter number.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top