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

Setting focus of page to a Div

Hello,
In my site I have a link and you click on it, it runs a javascript function where it gets makes a div visable. This is so people can click the link and get a defintion of a word.
Here is the link:

[HTML]<a href="#" onclick="toggle_visibility('processIslands');">(Wh at are Process Islands?)</a>
[/HTML]

Here is the Div:
[HTML] <div id="processIslands" style="display:none"> Text in the Div </div>
[/HTML]
And here is the function that is called:
Expand|Select|Wrap|Line Numbers
  1.     function toggle_visibility(id) {
  2.        var div = document.getElementById(id);
  3.        if(div.style.display == 'block')
  4.           div.style.display = 'none';
  5.        else
  6.           div.style.display = 'block';
  7.  
  8.     }
  9.  
My problem, is that when I use this as it is, it will show the div, but then it jumps to the top of the page. How can I set the focus of the page to that Div so the user doesn't have to scroll down and find where they were?

I am using asp.net C# Visual Studio 2005.

Thanks!
Mar 12 '08 #1
3 2848
acoder
16,027 Expert Mod 8TB
Just add return false to prevent the link being followed to #:
[HTML]<a href="#" onclick="toggle_visibility('processIslands'); return false;">(What are Process Islands?)</a>
[/HTML]
Mar 13 '08 #2
Thanks for that, It helped with that problem, but I sill was wondering how to set the focus to a div when a link is clicked. The scenario is a glossary, and when the user clicks on a word, they are focused on that words definition on the page. How would I go about doing that?

Thanks!
Mar 19 '08 #3
acoder
16,027 Expert Mod 8TB
Use <a name="#something"> next to the div to link to it, then use that in the href of the link and remove the "return false" in the onclick:[HTML]<a href="#something" onclick="toggle_visibility('processIslands');">(Wh at are Process Islands?)</a>
[/HTML]Replace "something" with something meaningful.
Mar 19 '08 #4

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

Similar topics

20
by: Arne | last post by:
During testing <div style="overflow:auto;"> in CSS I noticed the mousewheel would work in Mozilla only after I made a <a href="#">some text</a> link and clicked on that, within the div. It...
1
by: Rachel Suddeth | last post by:
I have an form where the whole display is a tab control (well, that plus a status bar.) I want to set the focus to the first TextBox on the first TabPage when it loads. I tried to put that into...
3
by: Steve Yerkes | last post by:
There seems to be way too much confusion over how to set focus on the a field using a field validator. I looked all over the web and found people trying to do this, but not getting anywhere. There...
1
by: test test | last post by:
Hi, How can I set focus to a particular textbox on an aspx page in vb code? My problem is caused by the page updating when a user clicks a command button and I execute code (like updating a...
12
by: CLEAR-RCIC | last post by:
Hi, I'm having problems setting focus to a textbox on a web user contol on an asp.net web page. The following script works on normal asp.net pages: <script language="javascript"> function...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for...
5
by: Finn Stampe Mikkelsen | last post by:
Hi How can i set a focus to a textbox in my codebehind page?? I have this WebForm, that takes information from a user and 2 buttons on the form. One that takes action on the entered...
4
by: Jason | last post by:
Hi, Here's the scenario: I have a web application that has window A and window B. A user has both window A and B open - window A is in the foreground and window B is behind it. If the...
3
by: kelvin.koogan | last post by:
I have a number of controls on a tab page. I want to validate them all when the user tries to leave the tab. I then want to highlight the first control which fails validation. How can I do this? I...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.