473,383 Members | 1,737 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,383 software developers and data experts.

two hrefs and function call

all I want to do is add the ability for an image to take the user
further down a page (href="#bottom").

Anyone tell me how to do this?

==the code below works perfectly===

My code on an image:

<a
onclick="SwapImage('no1','','/images/1.gif','no2','','../../../images/common/2-up.gif',1);return
showPic(this);" href="/images/sample2.gif" title="Logo"><img
src="../../../images/common/2.gif" name="no2" width="27" height="33"
id="no2" /></a>

and the accompanying javscript:
function showPic (whichpic) {
if (document.getElementById) {
document.getElementById('placeholder').src = whichpic.href;
if (whichpic.title) {
document.getElementById('desc').childNodes[0].nodeValue =
whichpic.title;
} else {
document.getElementById('desc').childNodes[0].nodeValue =
whichpic.childNodes[0].nodeValue;
}
return false;
} else {
return true;
}
}

Jul 23 '05 #1
4 2677
Gagan Diesh wrote:
all I want to do is add the ability for an image to take the user
further down a page (href="#bottom").
Read up on the <a> element:

<URL:http://www.w3.org/TR/html4/struct/links.html#edef-A>

Anyone tell me how to do this?
Replace your current href with one that points to the anchor
further down the page.

==the code below works perfectly===

My code on an image:

<a
onclick="SwapImage('no1','','/images/1.gif','no2','','../../../images/common/2-up.gif',1);return
showPic(this);" href="/images/sample2.gif" title="Logo"><img


... href="#bottom" ...

And then at the 'bottom' (somewhere further down your page):

<a name="bottom">Here is the bottom of the page</a>

[...]

--
Rob
Jul 23 '05 #2
Gagan Diesh wrote:
all I want to do is add the ability for an image to take the user
further down a page (href="#bottom").
Would you like it that when a user clicks on the image, a new
picture is displayed in the current page inside the
'placeholder' element?. And because the new image may be bigger
than the window size, you'd like to scroll to the bottom of the
image?

And if JS is not available, or the user's browser doesn't
support your script, navigate to the image anyway?

Anyone tell me how to do this?

Put an anchor below your image, then as the last line of your
onclick, change document.location to the anchor which can be
added thusly:

...
<img id="placeholder" src="" alt="">
<a name="bottom">Bottom of the image</a>
...
<URL:http://www.w3.org/TR/html4/struct/links.html#edef-A>
My code on an image:

<a
onclick="SwapImage('no1','','/images/1.gif','no2','','../../../images/common/2-up.gif',1);return
showPic(this);" href="/images/sample2.gif" title="Logo">
<a href="/images/sample2.gif"
title="Logo"
onclick="
SwapImage('no1','','/images/1.gif','no2','',
'../../../images/common/2-up.gif',1);
var x = showPic(this);
document.location = '#bottom';
return x;
"><img ...

Note that the 'return' is moved to after the document location
change.
<img
src="../../../images/common/2.gif" name="no2" width="27" height="33"
id="no2" /></a>

and the accompanying javscript:
function showPic (whichpic) {
if (document.getElementById) {
document.getElementById('placeholder').src = whichpic.href;
why not forget getElementById at this step (move it down a bit)
and use the images collection:

document.images['placeholder'].src = whichpic.href;
if (whichpic.title) {
document.getElementById('desc').childNodes[0].nodeValue =
whichpic.title;
} else {
document.getElementById('desc').childNodes[0].nodeValue =
whichpic.childNodes[0].nodeValue;
}
and do your getElementById thing here:

if (document.getElementById) {
var d = document.getElementById('desc').childNodes[0];
if (whichpic.title) {
d.nodeValue = whichpic.title;
} else {
d.nodeValue = whichpic.childNodes[0].nodeValue;
}

or more concisely:

if (document.getElementById) {
var d = document.getElementById('desc').childNodes[0];
d.nodeValue = whichpic.title ||
whichpic.childNodes[0].nodeValue;
}

It's easier on the eye, also the images collection is likely
more widely supported (just?) than getElementById, so if it
fails, at least there's still chance the image will display (but
without a title).

Choose whatever suits best.
return false;
} else {
return true;
}
}

There is no need for the 'else', if the script gets this far,
just return true unconditionally.

return false;
}
return true; }


Full code (tested in IE and Firefox):

<a href="1.gif"
title="Logo"
onclick="
SwapImage('no1','','/images/1.gif','no2','',
'../../../images/common/2-up.gif',1);
var x = showPic(this);
document.location='#bottom';
return x;
"><img src="1.gif"
name="no2" width="27" height="33"
id="no2"></a>
<input type="button" onclick="alert(document.images['no2']);"
value="click">
<script type="text/javascript">
function SwapImage(){
// just a dummy
}

function showPic (whichpic) {
document.images['placeholder'].src = whichpic.href;
if (document.getElementById) {
var d = document.getElementById('desc').childNodes[0];
d.nodeValue = whichpic.title ||
whichpic.childNodes[0].nodeValue;
return false;
}
return true;
}
</script>
<div style="height: 2000px">&nbsp;</div>
<img id="placeholder" name="placeholder" src="" alt="">

<!-- Must put something in 'desc' or script may fail in some
browsers 'cos childNodes[0] may not be created otherwise -->

<p id='desc'>&nbsp;</p>
<a name="bottom"></a>
--
Rob
Jul 23 '05 #3
RobG wrote:
[...]

<a href="/images/sample2.gif"
title="Logo"
onclick="
SwapImage('no1','','/images/1.gif','no2','',
'../../../images/common/2-up.gif',1);
var x = showPic(this);
document.location = '#bottom';
return x;
"><img ...

Note that the 'return' is moved to after the document location
change.
I had a think about this. The script should not return
anything, if JavaScript is not enabled, then the user will see
the image. If it is enabled, then the modified script below
will pretty much guarantee that they will see the new image

If the images collection is not supported, they will not see it
but how many browsers with JavaScript do not support the images
collection?

You are only dependent on getElementById for the caption, so
missing out on that is trivial. So just return false always and
be done with it:

...
showPic(this);
document.location = '#bottom';
return false;
"><img ...

And don't bother returning anything from the script:

[...] function showPic (whichpic) {
document.images['placeholder'].src = whichpic.href;
if (document.getElementById) {
var d = document.getElementById('desc').childNodes[0];
d.nodeValue = whichpic.title ||
whichpic.childNodes[0].nodeValue;
return false;
delete the return here.
}
return true;
and here.
}
</script>


[...]

You may wish to add some of the dynWrite functionality to assist
with support for non-getElementById browsers, but how many
don't support getElementById but do support the childNodes
collection?

<URL:http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html>

--
Rob
Jul 23 '05 #4
hi Rob:

thanks very much for your response--

Works really well on firefox, IE on Mac and PC.

The problem I am having is on Safari on a Mac.

am trying this with two image buttons, doing swaps and functions as
noted above.

1) Works fine for the first click.
2) When next button is pressed, the entirepage refreshes, and then
jupms down to the anchor tag (clumsy but I could deal with that)
3) When the first button is clicked AGAIN, things really break down!
Image swaps correctly for a moment sometimes, but then page refreshes
and a broken link shows up for the image that was supposed to be swaped
(Showpic image)

I am trying this online but is for a protected site. I am happy to mail
you the link if you want to take a look. you can email me at
gdiesh[a]gmail.com

Jul 23 '05 #5

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

Similar topics

8
by: Michelle | last post by:
Hi all, I was wondering if I can incorporate a variable (actually a calculation) in an href statement such as: print "<a href='calendar.php?month = $month-1'>go back a month</a> I wouldn't...
6
by: Andy Fish | last post by:
Hi, I want to use an anchor tag to invoke some javascript and I've read that it's bad form to use <a href="javascript:foo()"> I've read endless usenet posts and hint sites on the net, they all...
11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.