How do I place a dynamic value in the HREF

I

Iain

Hi All

My apologies if this appears to be simple to some of you but I have
very little experience of javascript and I cannot work this one out,

The code below is a nice piece of code I found on the web to rotate a
set of images. It works very well.

However, I would like to place a value in the HREF which points to a
larger version of the image currently being displayed

Example

The image being displayed may be a thumbnail tn_image1.jpg
I would like the HREF point to the image image1.jpg (the images will
always be the same name as the thumbnails but without the tn_ prefix).

Any help would be gratefully received

Iain

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

<%@LANGUAGE="VBSCRIPT"%>
<%
DIM objFSO, objFile, objFileTextStream, ImageCount
Set objFSO = CreateObject("Scripting.FileSystemObject")
LPP=server.MapPath("teegan.txt")
Set objFile = objFSO.GetFile(LPP)
Set objFileTextStream = objFile.OpenAsTextStream(1)
%>

<html>
<head>
<script language="JavaScript">
<!-- // Hide from old browsers --
/* This is a transition banner rotating script uses IE filters.
Netscape does a simple image swap */
var step=1
var speed=2 /* change speed below (in seconds) this value
determines how long each banner remains before it is changed */

/* =========================== IMAGES ========================= */
/* Begin Edit Here
*/
/* Source found at
http://www.havenofbliss.com/javascript/banner.html */
/* Add images as needed, but remember to update the number of
images variable */
/* ============================================================ */

<%
ImageCount=1

Do while objFileTextStream.AtEndOfStream <> True
StrLine=objFileTextStream.ReadLine
if StrLine<>"" then
%>
var image<%=ImageCount%>=new Image()
image<%=ImageCount%>.src='<%=trim(StrLine)%>'
<%
ImageCount=ImageCount+1
end if
loop
objFileTextStream.Close
%>
var number_of_images = <%=ImageCount-1%>
var name_of_image = <%=trim(StrLine)%>

window.onerror=reapply

function reapply()
{
/* Incase of an error, restart banner rotation */
setTimeout("slideit()",2000);
return true;
}

function slideit()
{
if (!document.images)
return;
if (document.all)
slide.filters.blendTrans.apply();
document.images.slide.src=eval("image" + step + ".src");
if (document.all)
slide.filters.blendTrans.play();
if (step < number_of_images)
step++;
else
step=1;
if (document.all)
setTimeout("slideit()", speed * 1000 + 3000);
else
setTimeout("slideit()", speed * 1000);
}
</script>

<title>Rotating Images</title>
</head>

<body onLoad="slideit();">
<!-- The following image tag is the place holder for the banner
-->
<br><br><br><br><br>
<center>
<A HREF = HOW DO I DERIVE THIS>
<IMG name = slide src = "background001.jpg" style =
"FILTER: blendTrans(duration = 3)"><br>IMAGE NAME</A>
</center>
</body>
</html>
 
R

Randy Webb

Iain said the following on 3/11/2006 2:49 AM:
Hi All

My apologies if this appears to be simple to some of you but I have
very little experience of javascript and I cannot work this one out,

The code below is a nice piece of code I found on the web to rotate a
set of images. It works very well.

It's hard to tell since you didn't post just the client side code but
you posted the server side code as well.
However, I would like to place a value in the HREF which points to a
larger version of the image currently being displayed

Example

The image being displayed may be a thumbnail tn_image1.jpg
I would like the HREF point to the image image1.jpg (the images will
always be the same name as the thumbnails but without the tn_ prefix).

Any help would be gratefully received

Post just the HTML that is sent to the browser. But most of the code
below is trash.
Iain

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

<%@LANGUAGE="VBSCRIPT"%>
<%
DIM objFSO, objFile, objFileTextStream, ImageCount
Set objFSO = CreateObject("Scripting.FileSystemObject")
LPP=server.MapPath("teegan.txt")
Set objFile = objFSO.GetFile(LPP)
Set objFileTextStream = objFile.OpenAsTextStream(1)
%>

<html>
<head>
<script language="JavaScript">

<!-- // Hide from old browsers --

"old browsers"? They haven't existed in quite some time, stop trying to
"hide" scripts - it causes more problems than it could solve.
/* This is a transition banner rotating script uses IE filters.
Netscape does a simple image swap */

And what about Opera, Mozilla, Firefox, Camino, ICEBrowser, etc...
var step=1
var speed=2 /* change speed below (in seconds) this value
determines how long each banner remains before it is changed */

/* =========================== IMAGES ========================= */
/* Begin Edit Here
*/
/* Source found at
http://www.havenofbliss.com/javascript/banner.html */
/* Add images as needed, but remember to update the number of
images variable */

Any script that makes you update the number of images is a good sign
that its junk. If nothing else, have your server side script generate
that code.

/* ============================================================ */

<%
ImageCount=1

Do while objFileTextStream.AtEndOfStream <> True
StrLine=objFileTextStream.ReadLine
if StrLine<>"" then
%>
var image<%=ImageCount%>=new Image()
image<%=ImageCount%>.src='<%=trim(StrLine)%>'
<%
ImageCount=ImageCount+1
end if
loop
objFileTextStream.Close
%>
var number_of_images = <%=ImageCount-1%>
var name_of_image = <%=trim(StrLine)%>

window.onerror=reapply

function reapply()
{
/* Incase of an error, restart banner rotation */
setTimeout("slideit()",2000);
return true;
}

function slideit()
{
if (!document.images)
return;
if (document.all)
slide.filters.blendTrans.apply();
document.images.slide.src=eval("image" + step + ".src");

Just that one line above makes this entire script junk. eval schmeval,
its evil.

document.images.slide.src = window['image' + step + ".src"];

if (document.all)
slide.filters.blendTrans.play();
if (step < number_of_images)
step++;
else
step=1;
if (document.all)
setTimeout("slideit()", speed * 1000 + 3000);
else
setTimeout("slideit()", speed * 1000);
}
</script>

<title>Rotating Images</title>
</head>

<body onLoad="slideit();">
<!-- The following image tag is the place holder for the banner
-->
<br><br><br><br><br>
<center>
<A HREF = HOW DO I DERIVE THIS>

You Derive it with code, and it would be a lot easier to tell you how if
you posted the actual code going to the browser instead of the server
side code as well. And even better - a URL to a sample page.

But, it would have to be done in the slideit() function.

All in all, it looks like a crappy way to do a slide show.
 
I

Iain

Hi Randy

Thanks for your input.
The code posted is the complete asp page which does actually work. I
can accept your point that it may be a crappy way to do things but I
was merely attempting to find out - as someone who has relatively
little javascript experience - how to dynamically derive the name of
the HREF value.

I have been playing around with it but just could not get the damn
thing to work so I thought I would ask those who know ie the javascript
group folk like yourself.

I have managed to find quite a few examples of slideshows that actually
work but the reason I liked this example was because it is dynamic.
Change the contents of the external text file and you have a fresh set
of images for the slide show. No need to physically change the source.

In addition, I am learning what is good bad and ugly from the examples


Iain
 
R

Randy Webb

Iain said the following on 3/11/2006 3:52 AM:

Hi Iain,

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
Thanks for your input.
The code posted is the complete asp page which does actually work. I
can accept your point that it may be a crappy way to do things but I
was merely attempting to find out - as someone who has relatively
little javascript experience - how to dynamically derive the name of
the HREF value.

Post a sample URL to a page generated by that ASP code. It makes writing
client side code a lot simpler.
I have been playing around with it but just could not get the damn
thing to work so I thought I would ask those who know ie the javascript
group folk like yourself.

<a id="myLink" href="noScripting.html">

And then in your function slideit(), find this line:

document.images.slide.src=eval("image" + step + ".src");

Changing it to the line I gave you probably isn't going to work if its
just an image name - a string.

But, to change the href you do something like this:

document.getElementById('myLink').href = newHREF;

Where newHREF is a variable that contains the href to the big image. How
you would go about getting that from the rest of your script depends -
directly - on the code your ASP page is outputting. That is why I asked
for a sample URL.

You show me what your ASP is outputting and I can show you a better
script and it will do what you want, a lot easier.
I have managed to find quite a few examples of slideshows that actually
work but the reason I liked this example was because it is dynamic.
Change the contents of the external text file and you have a fresh set
of images for the slide show. No need to physically change the source.

I wrote one in PHP for a friend about 3 years ago that you didn't even
have to give it a text file. It read the directory and got the filenames
itself. All you had to do was drop in the thumbnail and big image, it
did the rest.

So, post a URL to a sample page that uses your script.
 
T

TheBagbournes

Randy said:
Just that one line above makes this entire script junk. eval schmeval,
its evil.

document.images.slide.src = window['image' + step + ".src"];

I don't think that would work. I think you'd need

document.images.slide.src = window["image" + step].src;
 
R

Randy Webb

TheBagbournes said the following on 3/11/2006 6:11 AM:
Randy said:
Just that one line above makes this entire script junk. eval schmeval,
its evil.

document.images.slide.src = window['image' + step + ".src"];

I don't think that would work. I think you'd need

document.images.slide.src = window["image" + step].src;

I noted in my second reply that it probably wasn't what was needed.
Without seeing the client side code without the server side code I lost
interest in trying to wade through that garbage code to figure it out :)
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Sat, 11 Mar
2006 15:57:59 remote, seen in Randy Webb
TheBagbournes said the following on 3/11/2006 6:11 AM:
Randy said:
Just that one line above makes this entire script junk. eval schmeval,
its evil.

document.images.slide.src = window['image' + step + ".src"];

I don't think that would work. I think you'd need

document.images.slide.src = window["image" + step].src;

I noted in my second reply that it probably wasn't what was needed.
Without seeing the client side code without the server side code I lost
interest in trying to wade through that garbage code to figure it out :)

That's your problem. The OP clearly stated his negligible level of
expertise; it is the source code that he needs to change.

He might do better to ask in an ASP group.


AFAICS, this line changes the visible image

document.images.slide.src=eval("image" + step + ".src");

and the need therefore is to compute, at the same place in the code, an
analogous string referring to the larger image and to make it into a
link. The latter could perhaps be done with DynWrite (FAQ 4.15) into a
div or by a DOM-type means. FAQ 4.40, 4.39.
 
R

Randy Webb

Dr John Stockton said the following on 3/12/2006 1:28 PM:
JRS: In article <[email protected]>, dated Sat, 11 Mar
2006 15:57:59 remote, seen in Randy Webb
TheBagbournes said the following on 3/11/2006 6:11 AM:
Randy Webb wrote:
Just that one line above makes this entire script junk. eval schmeval,
its evil.

document.images.slide.src = window['image' + step + ".src"];
I don't think that would work. I think you'd need

document.images.slide.src = window["image" + step].src;
I noted in my second reply that it probably wasn't what was needed.
Without seeing the client side code without the server side code I lost
interest in trying to wade through that garbage code to figure it out :)

That's your problem.

So, it's my problem that I don't want to wade through the OP's garbage
code? Wow, thanks for the insight.

You couldn't be more wrong.
The OP clearly stated his negligible level of expertise;

Thats *his* problem, not mine.
it is the source code that he needs to change.


Really? I would never have though that to make a script do something
different that you would need to change the source code.

Your mastery of the obvious is wonderful to see in action.
He might do better to ask in an ASP group.

Ask in an ASP group how to modify client-side code to do something
different? Wow, your insight never ceases to amaze me.
AFAICS, this line changes the visible image

document.images.slide.src=eval("image" + step + ".src");

Again, your mastery of the obvious impresses me. The problem wasn't in
the first half of that line, the problem is in the second half.
and the need therefore is to compute, at the same place in the code, an
analogous string referring to the larger image and to make it into a
link.

Wow, you finally figured it out. I am amazed.

But, there is no "need" to do it at that point in the function. In fact,
you don't even have to do it in that function at all.
The latter could perhaps be done with DynWrite (FAQ 4.15) into a
div or by a DOM-type means. FAQ 4.40, 4.39.

So, your solution to change the href of a link is to DynWrite it all
into a div tag? I am glad I don't have to pay you for reasonable
solutions, I would either go broke or fire you the first day.

<a href="nowhere.html" onclick="
document.location.href = document.images['myImage'].src.substring(3);
return false;
"><img name="myImage"></a>

Your pedantic ignorance amazes me sometimes John.
 
I

Iain

Thanks for all the comment - I would have replied earlier but I was
away.


I would like to address the comments of Randy Webb.

The code I displayed (and that was the complete page of code) may be
Crap as you put it and there may be very many better ways to solve the
problem (after looking further I have found many other better solutions
for slide shows) but that is not the point.

This is a discussion forum where people who have particular skills are
able to advise people without those skills on how to solve a problem.
Forums work well when people co-operate.

If you do not feel inclined to assist then why not refrain from making
comments that can at best be described as lacking constructive content.

You made the decision to take the time to comment on someone else's
code (I did indicate that I had found the code on the web although I
ommited to mention that I had added the ASP) and although I did
indicate that I was new to Javascript - and frankly I am relatively new
to web page design - you felt the need to vent your spleen.

If you wish to blow off steam then please do so elswhere otherwise
stick to constructive comment.

Iain
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Mon, 20 Mar 2006 23:50:51 remote, seen in
news:comp.lang.javascript said:
Thanks for all the comment - I would have replied earlier but I was
away.


I would like to address the comments of Randy Webb.

The code I displayed (and that was the complete page of code) may be
Crap as you put it and there may be very many better ways to solve the
problem (after looking further I have found many other better solutions
for slide shows) but that is not the point.

This is a discussion forum where people who have particular skills are
able to advise people without those skills on how to solve a problem.
Forums work well when people co-operate.

If you do not feel inclined to assist then why not refrain from making
comments that can at best be described as lacking constructive content.

You made the decision to take the time to comment on someone else's
code (I did indicate that I had found the code on the web although I
ommited to mention that I had added the ASP) and although I did
indicate that I was new to Javascript - and frankly I am relatively new
to web page design - you felt the need to vent your spleen.

If you wish to blow off steam then please do so elswhere otherwise
stick to constructive comment.

If you had the wisdom to heed
Hi Iain,

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
<URL: http://www.safalra.com/special/googlegroupsreply/ >

then you might find that the experts would show a continuing interest in
your problem.

You have after all yourself written
Forums work well when people co-operate.


Read the newsgroup FAQ.
 
R

Randy Webb

Iain said the following on 3/21/2006 2:50 AM:
Thanks for all the comment - I would have replied earlier but I was
away.

Did you forget how to read and reply while you were gone? In case you
did, here it is again:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
I would like to address the comments of Randy Webb.

Hot diggity dog, I get a post of my own.
The code I displayed (and that was the complete page of code) may be
Crap as you put it and there may be very many better ways to solve the
problem (after looking further I have found many other better solutions
for slide shows) but that is not the point.

It wasn't crap because I said it was crap, it was crap because it's
crappy code.
This is a discussion forum where people who have particular skills are
able to advise people without those skills on how to solve a problem.

You couldn't be more wrong. This is Usenet, comp.lang.javascript in
particular, where we discuss scripting. If you happen to get an answer
to your question, then great. If you don't, get over it.
Forums work well when people co-operate.

"Forum"? What forum? This is Usenet.

But, since you mention cooperation, let me ask which part it was where I
wasn't cooperating. Was it where you didn't quote what you were replying
to? Or, was it where I asked for a URL to the client-side code and you
didn't provide it? Or, was it when I posted code in reply to JRS that
solved your problem? Or, was it when I said "You show me what your ASP
is outputting and I can show you a better script and it will do what you
want, a lot easier. " that I wasn't "cooperating">

Which place was it that *I* was the one not cooperating?

<a href="nowhere.html" onclick="
document.location.href = document.images['myImage'].src.substring(3);
return false;
"><img name="myImage"></a>

Or, did you cooperate and miss that code?
If you do not feel inclined to assist then why not refrain from making
comments that can at best be described as lacking constructive content.

You are amazing.....
You made the decision to take the time to comment on someone else's
code (I did indicate that I had found the code on the web although I
ommited to mention that I had added the ASP) and although I did
indicate that I was new to Javascript - and frankly I am relatively new
to web page design - you felt the need to vent your spleen.

You think that was a vent? If you think that was a rant/vent then I
would hate to know your reaction to a real rant/vent. As the saying goes
"You ain't seen nothin' yet".
If you wish to blow off steam then please do so elswhere otherwise
stick to constructive comment.

GFY and then FOAD pal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top