473,624 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="VB SCRIPT"%>
<%
DIM objFSO, objFile, objFileTextStre am, ImageCount
Set objFSO = CreateObject("S cripting.FileSy stemObject")
LPP=server.MapP ath("teegan.txt ")
Set objFile = objFSO.GetFile( LPP)
Set objFileTextStre am = objFile.OpenAsT extStream(1)
%>

<html>
<head>
<script language="JavaS cript">
<!-- // 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 objFileTextStre am.AtEndOfStrea m <> True
StrLine=objFile TextStream.Read Line
if StrLine<>"" then
%>
var image<%=ImageCo unt%>=new Image()
image<%=ImageCo unt%>.src='<%=t rim(StrLine)%>'
<%
ImageCount=Imag eCount+1
end if
loop
objFileTextStre am.Close
%>
var number_of_image s = <%=ImageCount-1%>
var name_of_image = <%=trim(StrLine )%>

window.onerror= reapply

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

function slideit()
{
if (!document.imag es)
return;
if (document.all)
slide.filters.b lendTrans.apply ();
document.images .slide.src=eval ("image" + step + ".src");
if (document.all)
slide.filters.b lendTrans.play( );
if (step < number_of_image s)
step++;
else
step=1;
if (document.all)
setTimeout("sli deit()", speed * 1000 + 3000);
else
setTimeout("sli deit()", speed * 1000);
}
</script>

<title>Rotati ng 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(dura tion = 3)"><br>IMAGE NAME</A>
</center>
</body>
</html>

Mar 11 '06 #1
10 3512
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="VB SCRIPT"%>
<%
DIM objFSO, objFile, objFileTextStre am, ImageCount
Set objFSO = CreateObject("S cripting.FileSy stemObject")
LPP=server.MapP ath("teegan.txt ")
Set objFile = objFSO.GetFile( LPP)
Set objFileTextStre am = objFile.OpenAsT extStream(1)
%>

<html>
<head>
<script language="JavaS cript">
<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 objFileTextStre am.AtEndOfStrea m <> True
StrLine=objFile TextStream.Read Line
if StrLine<>"" then
%>
var image<%=ImageCo unt%>=new Image()
image<%=ImageCo unt%>.src='<%=t rim(StrLine)%>'
<%
ImageCount=Imag eCount+1
end if
loop
objFileTextStre am.Close
%>
var number_of_image s = <%=ImageCount-1%>
var name_of_image = <%=trim(StrLine )%>

window.onerror= reapply

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

function slideit()
{
if (!document.imag es)
return;
if (document.all)
slide.filters.b lendTrans.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.b lendTrans.play( );
if (step < number_of_image s)
step++;
else
step=1;
if (document.all)
setTimeout("sli deit()", speed * 1000 + 3000);
else
setTimeout("sli deit()", speed * 1000);
}
</script>

<title>Rotati ng 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.javas cript 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.c om, 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="noScripti ng.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.getEle mentById('myLin k').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.javas cript 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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 11 '06 #6
JRS: In article <7a************ ********@comcas t.com>, dated Sat, 11 Mar
2006 15:57:59 remote, seen in news:comp.lang. javascript, Randy Webb
<Hi************ @aol.com> posted :
TheBagbourne s 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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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************ ********@comcas t.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.h tml" onclick="
document.locati on.href = document.images['myImage'].src.substring( 3);
return false;
"><img name="myImage"> </a>

Your pedantic ignorance amazes me sometimes John.

--
Randy
comp.lang.javas cript 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************ **********@t31g 2000cwb.googleg roups.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.c om, 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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 21 '06 #10

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

Similar topics

1
2549
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
2748
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 %>' runat="server"></uc1:BusinessUnit>
0
1089
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 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
1
2587
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 retrive value from array. I am very poore in javascript please help me. coding is like this
3
2668
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 of xml data type. i was successful in inserting the static value inside my table.by following code:--- UPDATE docs
3
11263
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
4853
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 the infromation (like images) out of the database which corresponds with that ID and present that in the DHTML pop-up. The pop-up code i have: <a href="##" onclick="popup_show('popup', 'popup_drag', 'popup_exit', 'screen-center', -400, 100);"> ...
1
1575
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 from the dropdown using ajax and how to display the details. give suggestions to do it.
1
2021
by: Vinay Vittal | last post by:
Dear all, I want set the dynamic value for the offset attribute of logic:iterator
0
8177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.