473,785 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="SwapIm age('no1','','/images/1.gif','no2','' ,'../../../images/common/2-up.gif',1);retu rn
showPic(this);" href="/images/sample2.gif" title="Logo"><i mg
src="../../../images/common/2.gif" name="no2" width="27" height="33"
id="no2" /></a>

and the accompanying javscript:
function showPic (whichpic) {
if (document.getEl ementById) {
document.getEle mentById('place holder').src = whichpic.href;
if (whichpic.title ) {
document.getEle mentById('desc' ).childNodes[0].nodeValue =
whichpic.title;
} else {
document.getEle mentById('desc' ).childNodes[0].nodeValue =
whichpic.childN odes[0].nodeValue;
}
return false;
} else {
return true;
}
}

Jul 23 '05 #1
4 2696
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="SwapIm age('no1','','/images/1.gif','no2','' ,'../../../images/common/2-up.gif',1);retu rn
showPic(this);" href="/images/sample2.gif" title="Logo"><i mg


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

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

<a name="bottom">H ere 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.locati on to the anchor which can be
added thusly:

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

<a
onclick="SwapIm age('no1','','/images/1.gif','no2','' ,'../../../images/common/2-up.gif',1);retu rn
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.locati on = '#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.getEl ementById) {
document.getEle mentById('place holder').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.getEle mentById('desc' ).childNodes[0].nodeValue =
whichpic.title;
} else {
document.getEle mentById('desc' ).childNodes[0].nodeValue =
whichpic.childN odes[0].nodeValue;
}
and do your getElementById thing here:

if (document.getEl ementById) {
var d = document.getEle mentById('desc' ).childNodes[0];
if (whichpic.title ) {
d.nodeValue = whichpic.title;
} else {
d.nodeValue = whichpic.childN odes[0].nodeValue;
}

or more concisely:

if (document.getEl ementById) {
var d = document.getEle mentById('desc' ).childNodes[0];
d.nodeValue = whichpic.title ||
whichpic.childN odes[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.locati on='#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.getEl ementById) {
var d = document.getEle mentById('desc' ).childNodes[0];
d.nodeValue = whichpic.title ||
whichpic.childN odes[0].nodeValue;
return false;
}
return true;
}
</script>
<div style="height: 2000px">&nbsp;</div>
<img id="placeholder " name="placehold er" 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.locati on = '#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.locati on = '#bottom';
return false;
"><img ...

And don't bother returning anything from the script:

[...] function showPic (whichpic) {
document.images['placeholder'].src = whichpic.href;
if (document.getEl ementById) {
var d = document.getEle mentById('desc' ).childNodes[0];
d.nodeValue = whichpic.title ||
whichpic.childN odes[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.c om/faq/faq_notes/alt_dynwrite.ht ml>

--
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
1684
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 think that this is the correct syntax, but the basic idea is there.
6
2536
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 suggest different things and I can't get any kind of consistency, and I can't find any solution that works properly for IE, opera and mozilla. many of the recommended solutions go something like this:
11
2715
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
7678
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 like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
13
4150
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 sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain amount of floating point work was approximately. To attempt to do this I made a program that...
23
7818
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 called, can be a genuine no-op. Consider: typedef int(*polymorphic_func)(int param);
3
3656
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' that takes arguments of type (void *) because the ADT must be able to deal with any type of data. In my actual code, I will code the function to take arguments of their real types, then when I pass this pointer through an interface function, I...
9
3277
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 function are of type int. (My question has nothing to do with the definition of the function foo, so don't bother about it.) If I call the function as: foo(2,3,4,5,6,7,8);/*More arguments than expected*/
6
5931
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 or without parms. I know that any function that is passed to Eval() must be declared Public. It can be a Sub or Function, as long as it's Public. I even have it where the "function" evaluated by Eval can be in a form (class) module or in a standard...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10336
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
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8978
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
7502
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
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
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.