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!

Focus on DIV -- (JQuery)

Status
Not open for further replies.

JRB-Bldr

Programmer
May 17, 2001
3,281
US
I was reading thread216-853621 where it mentions setting an Anchor point in the script and using that to do a .focus() on.
And that is precisely what I am trying to do.

In general that makes sense, but, as a newbie to JQuery, I have a question regarding the syntax needed to do that.

Doing some selective cut-and-paste from that other posting I come up with the following suggested code.

Code:
  <div class="section wrap-up hidden">
     <a name="FOCUS_HERE"></a>
     <div ...> 
         ... 
     </div>
  </div>
  
  // and some where else doing
  [b]FOCUS_HERE.focus();[/b]

My question is -- since the Anchor point ("FOCUS_HERE") is within a DIV Section do I need to modify the syntax of the .focus() command line?

Or, as an Anchor point, can it be referenced all by itself (as shown in the possible code above)?

Thanks,
JRB-Bldr






 
does focus() really work? I'd be amazed.

to 'focus' to a particular point I think I'd do this
Code:
$[COLOR=#990000]([/color]window[COLOR=#990000]).[/color][b][COLOR=#000000]scrollTop[/color][/b][COLOR=#990000]([/color]$[COLOR=#990000]([/color][COLOR=#FF0000]'#nameOfAnchor'[/color][COLOR=#990000]).[/color][b][COLOR=#000000]position[/color][/b][COLOR=#990000]().[/color]top[COLOR=#990000]);[/color]
 
does focus() really work?

I know it works fine for Input and Select objects, but I have no idea if it works on <div>'s or <a>'s.

I just want a user to enter a value into a Yes/No Select and, If they entered a "YES", either go on from where they are.
OR, if they entered a "NO", Jump forward to another point a good bit further down the page to another <div> (above which I have my Anchor "FOCUS_HERE" located).

Code:
<div class="section wrap-up hidden">
     <a name="FOCUS_HERE"></a>
     <div ...> 
         <p>
           Thank you.
         </p>
     </div>
</div>

Some web searching for an answer led me to believe that focus() might work if it was to an Anchor.

I even found another approach that web references said should work
document.getElementById('#nameOfAnchor').scrollIntoView(true)
and yet other references indicated that the scrollIntoView might not work.

As with most languages there are usually a number of approaches that should work.
But with conflicting information I am not sure which approach to use.

Thanks,
JRB-Bldr






 
what is wrong with the code that I posted? have you tried that and found that it did not work for you? what error messages did you receive?
 
will the most basic html suffice

Code:
Do you want to continue? <a href="#yes">yes</a> | <a href="#no">no</a>

<a name="yes"></a>
 "You have 13 hours in which to solve the labyrinth, or your baby brother...is mine!"

<!-- Somewhere far far down the page.  Some might say, the "Oubliette" -->

<a name="no"></a>
  "Go back to your room.  Play with your toys and costumes.  Forget about the baby!"

-Geates
 
i had assumed the OP wanted to use jQuery from his post.

to avoid the click requirement and automate the movement in javascript you could always just use windows.location

Code:
windows.location.hash="nameOfAnchor";

assuming this to be a wizard type interface, then it might well be better to design the form using multiple pages of a tabbed interface via a jquery plugin. then the migration is sorted out for you. e.g.
you then change the action of the 'next' button depending on user choices.

but for a simple jump-to using vanilla javascript rather than jquery, the above will work (as would clicking on the link). for jQuery solution, see my post above.
 
what is wrong with the code that I posted?

I never said that anything was wrong with it.

I was only answering your question - "does focus() really work?"
and going on to explain why I was confused with possibly conflicting info from the web.

I will try it and see how it works.

Thanks,
JRB-Bldr


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top