473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do I place a dynamic value in the HREF

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>

Mar 11 '06 #1
10 3482
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">
<script type="text/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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Mar 11 '06 #2
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

Mar 11 '06 #3
Iain said the following on 3/11/2006 3:52 AM:
Hi Randy
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/ >
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 11 '06 #4
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;
Mar 11 '06 #5
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 :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 11 '06 #6
JRS: In article <7a********************@comcast.com>, dated Sat, 11 Mar
2006 15:57:59 remote, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
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. 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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 12 '06 #7
Dr John Stockton said the following on 3/12/2006 1:28 PM:
JRS: In article <7a********************@comcast.com>, dated Sat, 11 Mar
2006 15:57:59 remote, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 13 '06 #8
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

Mar 21 '06 #9
JRS: In article <11**********************@t31g2000cwb.googlegroups .com>
, dated Mon, 20 Mar 2006 23:50:51 remote, seen in
news:comp.lang.javascript, Iain <Em**************@gmail.com> posted :
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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 21 '06 #10
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.
<URL: http://www.safalra.com/special/googlegroupsreply/ >

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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 22 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: D Mineer | last post by:
HEre is my code function passVal(p,q,r){ with (window.opener.form1) { bldr_cmpny.value=p bldr_cotel.value=q; bldr_lcse.value=r; } window.close(); }
2
by: moid | last post by:
how to pass dynamic value to property in usercontrol im using this but its not working <uc1:BusinessUnit id="BusinessUnit1" Type='<%# type %>' POID='<%# poid %>'...
0
by: martin1 | last post by:
Hi, All, In the aspx page sqlDataSource section, I try to use dynamic value in selectCommand where condition, anyone knows how? or correct foramt to use the dcnid value Dim dcnid=12 ...
1
by: mandakini | last post by:
Hello freinds I am working on this url http://72.36.156.243/compbuild.php Here I am using ifram and displaying dynamic value I don't know how to use iframe as array how to assign array and...
3
by: Mukesh | last post by:
sir, i am developing a database, which will store the users profile both personal and professional which includes the address, telephone, gender and etc. in my main table i have created a column...
3
by: Richard | last post by:
How is the result of query placed in a unbound textbox ? Suppose CriteriaLookups has columns TableName, KeyColumn, KeyValue, DataColumn Foo,x,11,xhat Bar,z,3,xyzzy And
5
by: richardgroenhhw | last post by:
Hi, I have a javascript pop-up code. I want this peace of code to pass a unique ID (which i get from the database) to that dhtml pop-up. So then i can do a select query with that unique ID and get...
1
by: techbytes | last post by:
hai, I have a dropdown which has dynamic values.When I select a particular value in the dropdown,i want to diaplay corresponding details . I donot know how to get the dynamic value...
1
by: Vinay Vittal | last post by:
Dear all, I want set the dynamic value for the offset attribute of logic:iterator
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.