Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript seem to reset the html page 2

Status
Not open for further replies.

Leland123

Programmer
Aug 15, 2001
402
US
I have an html form with an onclick <img src> something like this:

<img src ... ONCLICK="displayPhoto('
This calls a displayPhoto javascript function where the thumbnail is displayed as a large image using javascript's window.open() command.

The above is included in a shopping cart application where many products can be displayed on a single page. If the user has scrolled down the page to any depth, when he/she clicks on the thumbnail, the html page seems to be called and goes back to the top of the page, thus losing the user place on the html page. When the user closes the javascript window, he must again scroll down the html page to resume viewing products at the place he left off prior to clicking on the thumbnail, and this occur each time a new javascript window is opened from a thumbnail.

I'm hoping someone can give me a clue, or a simple javascript command, of how to keep the html page from going back to the top of the page each time the javascript is called.

Regards,

LelandJ

Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
i'm having a hard time believing your onclick call is actually in your img tag, and not in a surrounding anchor tag.

the functionality you're describing usually happens when you have something like this:

Code:
<a href="#" onclick="doSomething();">...</a>

The "#" is a named anchor, which will by default bring you back to the top of your page (in some browsers). the fix to this is implementing your code like the following:

Code:
<a href="#" onclick="doSomething(); [red]return false;[/red]">...</a>

note: the functionality you're describing should not occur if the onclick is in an img tag, as you say it is.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks for the advice. I'll give that a try, and see if it corrects the problem. The code is actually in a perl script, but the output, including the variables are streamed to the client's browser in pure html:

elsif ( $arraycolumns[ $loop_index ] eq "moreinfo1" )
{
if ( $therow[ $loop_index ] )
{
print qq
~
<td>
<INPUT type="image" src="$therow[$loop_index]" heigth="$oMy->{THUMBNAIL_HEIGHT}" width="$oMy->{THUMBNAIL_WIDTH}" name="displayPhoto" title="Display More Info 1" VALUE="" ONCLICK="displayPhoto('$oMy->{ THE_COMPANY }','$therow[$loop_index]')">
</td>

~;
}
else
{
print qq~<td>None</td>~;
}
}

I'll check back and let you know how it goes.

Regards,

LelandJ

Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
ahh, same thing - an input type of image will submit the form, producing similar results to the results i described above. try adding a return false if you don't need the form to submit.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
If I take the perl out, the html would look like:

<td>
<INPUT type="image" src=" heigth="150" width="150" name="displayPhoto" title="Display More Info 1" VALUE="" ONCLICK="displayPhoto('Picture Title',' </td>


Regards,

LelandJ

Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
so as i explained to you, add the return false.

Code:
<INPUT type="image" src="[URL unfurl="true"]http://www.smvfp.com/sm_cart_product_images/prod1.png"[/URL] heigth="150" width="150" name="displayPhoto" title="Display More Info 1" VALUE="" ONCLICK="displayPhoto('Picture Title','[URL unfurl="true"]http://www.smvfp.com/sm_cart_product_images/prod1.png')[/URL][red]; return false;[/red]">



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks cLFlaVA; the "return false;" worked.

Regards,

LelandJ

Leland F. Jackson, CPA
Software - Master (TM)
Nothing Runs Like the Fox
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top