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

Why a web Page associated with a JS moves to the top when JS is activated ?

296 100+
I have a unique question .

Suppose we attach a Javascript to a link.
When we click the link a JS function is called and the body of the web page moves to the top if we had scrolled down the page.

I want to stop the web page from going to the top.

How to do this ?
Jan 31 '07 #1
9 1418
pankajit09
296 100+
Please anyone .
Jan 31 '07 #2
acoder
16,027 Expert Mod 8TB
Post your code which does this, so that it can be altered.

One more thing: please do not bump up your thread if you have nothing new to say. Different time zones mean that responses cannot be immediate. If it's been 24 hours, then you might consider doing that, perhaps with a more detailed explanation including code (then I won't mind!)
Jan 31 '07 #3
pankajit09
296 100+
This is my code -->

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="/ps/js/prototype.js"></script>
  2. <script language="Javascript">
  3.     function getHTML(num) {
  4.         if(num == undefined) {
  5.             var num = document.getElementById('refid').value;
  6.         }
  7.         var num = num;
  8.         var url = '/cgi-bin/ps/srch.cgi';
  9.         var pars = 'num='+num+'&act=showattachedfilesection';
  10.         var myAjax = new Ajax.Updater( {success: 'placeholder'}, url, { method: 'get', parameters: pars, onFailure: reportError });
  11.     }
  12.  
  13.     function getSrchResults() {
  14.         document.getElementById('systemWorking').style.visibility = 'visible';
  15.         var textbox = document.getElementById('data').value;
  16.         var ex = document.getElementById('exact');
  17.         if(ex.checked) {
  18.             var exact = 1;
  19.         }
  20.         var a = document.getElementById('and');
  21.         if(a.checked) {
  22.             var and = 1;
  23.         }
  24.         var se = document.getElementById('sequence');
  25.         if(se.checked) {
  26.             var seq = 1;
  27.         }
  28.         var url = '/cgi-bin/ps/srch.cgi';
  29.         var pars = 'data='+textbox+'&exact='+exact+'&and='+and+'&seq='+seq+'&act=search';
  30.         var myAjax = new Ajax.Updater( {success: 'searchplaceholder'}, url, { method: 'get', parameters: pars,onFailure: reportError });
  31.     }
  32.  
  33.     function reportError(request) {
  34.         alert('Sorry. There was an error.');
  35.     }
  36.  
  37.     var myGlobalHandlers = {
  38.         onCreate: function(){
  39.             Element.show('systemWorking');
  40.         },
  41.         onComplete: function() {
  42.             if(Ajax.activeRequestCount == 0){
  43.                 Element.hide('systemWorking');
  44.             }
  45.         }
  46.     };
  47.  
  48.     Ajax.Responders.register(myGlobalHandlers);
  49. </script>
  50.  
  51. <table cellpadding="0" cellspacing="0" width="73%" align="center">
  52. <tr><td class="punchintitle" colspan="9">Search Database</td></tr>
  53. <tr>
  54. <td class="report" align="right" width="20%">Keywords&nbsp;</td>
  55. <td class="report" align="left" width="40%"><input type="textbox" id="data" size="40" maxlength="200"/></td>
  56. <td class="report" align="right">Exact</td>
  57. <td class="report"><input type="checkbox" id="exact"/></td>
  58. <td class="report" align="right">AND</td>
  59. <td class="report"><input type="checkbox" id="and"/></td>
  60. <td class="report" align="right" width="10%">Sequence</td>
  61. <td class="report"><input type="checkbox" id="sequence"/></td>
  62. <td class="report" align="right"><a href="#" onClick="getSrchResults();">Search</a></td>
  63. <td><div id='systemWorking' align="center" style="visibility:hidden;"><img src='/ps/imgs/animated-circle-ball.gif'></div></td>
  64. </tr>
  65. </table>
  66.  
  67. <br/>
  68. <div id="srchplaceholder"></div>
  69.  
  70. <br/><br/>
  71. <div id="placeholder"></div>
I am using Ajax to replace the "placeholders" present in the DIVs above .
Whenever I click on the Search link the page goes up.
I want the page to be at the current place .

The above code is present in a HTML template which gets values from a Perl CGI file.
Jan 31 '07 #4
pankajit09
296 100+
Also I don't think there is any need of code because this is a general phenomenon.
Jan 31 '07 #5
pankajit09
296 100+
I got the solution using anchors -->

<a href="#bottomanchor">Go to Bottom</a>

<a name="bottomanchor"></a>
Feb 1 '07 #6
acoder
16,027 Expert Mod 8TB
Glad you got your problem solved and thank you for posting and sharing your solution.
Feb 1 '07 #7
iam_clint
1,208 Expert 1GB
<a href="javascript: void(0)" onclick="whatever">
Feb 1 '07 #8
acoder
16,027 Expert Mod 8TB
<a href="javascript: void(0)" onclick="whatever">
Yes, looking back at the code, this is a much better solution. Using the anchors will achieve what you want but it's still moving to somewhere.
Change
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onClick="getSrchResults();">Search</a>
to
Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:void(0)" onClick="getSrchResults();">Search</a>
javascript:void(0) causes a dead link.
Feb 1 '07 #9
pankajit09
296 100+
ya you all are right .

But I want to move down so I used the anchors.

If I have to remain in that position then I will use your code.

Thanks for the code.
Feb 2 '07 #10

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

Similar topics

4
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a form with multiple pages on it. There is one text field on the third page of the form that I need the user to complete before leaving the form or moving...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
3
by: Geoff C Melbourne | last post by:
I'm new to asp.net. I have an ASP.Net form that contains literally 50 fields for the user to enter for a contacts details. All these fields are stored in the one table. So I have a class that...
0
by: pavan377 | last post by:
Hi folks, I got a requirement in my project where in when my application is activated another window should get activated and upon it my application should be present. Both should be in restored...
1
by: SammyBar | last post by:
Hi all, I'm having troubles with a Symbol 9000 device (Compact Framework v 1.1) when activating the barcode scanner from a window. The problem is related to the Activated event of the form which...
1
by: google | last post by:
I have a form with several subforms. Users enter the data, then on the parent there is a command button that runs code to generate a .pdf document from a report based on the data they are working...
4
by: intheshade | last post by:
hi! I'm trying to implement actionscript so that when the user moves the cursor, the page moves, revealing areas of the page that were previously outside the boundaries. basically, the user moves the...
1
by: ABCL | last post by:
Hi I have aspx page that has a html link on it( <a href="javascript:window.open('xxx.aspx')";..) When I click this link If should open new window usng javascript, But it gives me a message...
1
by: koren99 | last post by:
Hello, I have a gridview that is filled with a datasource & template fields dynamically. ( that has to be done because i ask the user for a datasource) anyway, i started out creating a static...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...

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.