473,326 Members | 2,255 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,326 software developers and data experts.

set <a> href to that of an image src

hi guys

please help this is well urgent and doing my head in

i want to change the href of an <a> tag to that of an image so they are both the same.

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. function setURL(){
  3. var image=document.getElementById('mainpic');
  4. var lnk=document.getElementById("link")
  5. lnk.href = image.src;
  6. }
  7.  
  8. </script>
  9.  
  10. <div id="loadarea">
  11. <a id="link" href="javascript:setURL()" rel="lightbox" style="border:0px">
  12. <img id="mainpic" src="http://fashionvault.esellerproimages.com/I/608/MCJ2895-1.jpg"  rel="lightbox" style="border:0px">
  13. </a>
  14. </div>
  15.  
the images are loaded dynamically from a database so i may not know the url to the image. when the user click the image it should open up in a lightbox at the moment the image never loads so i'm assuming that the javascript is not working.

i've googled this but can't find anything

please help guys

thanks in advance

:)
Sep 12 '07 #1
2 1979
Well, the javascript works as coded for me w/o errors. You may be having a problem b/c it will take 2 clicks for you to actually have the URL changed:

Click 1 calls setURL() which replaces the href="javascript:setURL();" with the appropriate image URL.

Click 2 then takes you directly to the image.

I have to add that I'm a bit confused -- if you know the URL of the image well enough to populate the src of the img tag, then why can't you apply that same technique to the href?
Sep 12 '07 #2
pbmods
5,821 Expert 4TB
Heya, Adam. Welcome to TSDN!

Please use CODE tags when posting source code:

[CODE=javascript]
JavaScript code goes here.
[/CODE]
Sep 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Lasse | last post by:
I have done this simple function, it seems to work as intended, to solve a problem i have had for a while. I couldnt find any sample around that was working for me. I would like to test it with...
1
by: Alan Illeman | last post by:
This is one of several macros I wish to display: <PRE CLASS="special macro> ;; ;; Reverse argument list ;; reverse_args MACRO arglist:req local txt, arg txt textequ <> % FOR arg, <arglist>
5
by: Derek Fountain | last post by:
I have a horizontal navigation bar, which is a single row table containing the right images. It "stretches" itself across the screen using a penultimate td like this: <td width="100%"...
11
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
2
by: Amir Eshterayeh | last post by:
Dear Friends I want to change the name of my css file dynamically so as Mr. Jos Branders helped me, I can change the <head> tag into an HTML control like this: <head id="myhead" runat="server">...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
0
by: yma | last post by:
Hi, I have a web.config file that contains <httpHandlers> section that causes "cannot load file..." error. If I delete this section, it is OK. Why did vb.net add this section? It does not add...
4
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi. I'm building an ASP.NET 2.0 web-app for a customer. The customer wants a background image that's 124k in size as the background for each page. I've recommended they use a smaller-size image,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.