Javascript problem

Posted by: dmob

Javascript problem - 30/09/2002 08:04

Hopefully someone can tell me how to do this. I have client side validation running in javascript. The function simply checks to see if the user entered an answer to each question on the page. If they did not answer one I would like to focus on that question. Here is my problem.

The page looks something like this:

<html>
<head></head>
<body>

1. What is your name?
<input name="full name" type="text">

2. What is your favorite color?
<input name="favcolor" type="text">

</body>
</html>

Within the validation function I can set focus to the 'fullname' input box or the 'favcolor' one, but I can't set focus to the question text. Setting focus to the input box will push the question text off of the top of the page and the user would have to scroll up to see what the question was again. Does this make sense?

Is there any way I could set anchor tags around the question text and then have the javascript focus on or jump to the anchor? If that can't be done, doesn anyone have another suggestion to accomplish what I am trying to do?

Thanks

Dennis
Posted by: wfaulk

Re: Javascript problem - 30/09/2002 08:34

Well, you can do internal links using <A NAME=xxx> tags (read the HTML spec on this), but I don't know that it'll necessarily work well.
Posted by: dmob

Re: Javascript problem - 30/09/2002 08:42

That's basically what I am trying to do (set internal links) but I don't know how to reference them within the javascript
Posted by: Anonymous

Re: Javascript problem - 30/09/2002 14:12

<a name="whatever">
</a>

document.whatever

I think that's how it goes. If "name=" doesn't work, try "id=".


Or try:

<div id="whatever"> </div>

If you still can't get it working, give some more detail on what exactly you want to do, and I'll take another look at it.


Posted by: XslamfaceX

Re: Javascript problem - 03/10/2002 08:24

javascript has a "scroll" function in which the page automatically scrolls to a certain point. you might want to look into that. but i don't really understand the whole script and how it works...it's hard to provide information.

another solution (depending on how you wrote the script) would be to set a variable to the place you wanted them to go.

ex.
function goThere(place){
document.href = "page.html#" + place;
}

i didn't try it out so it may have a bug or 2 but you get my drift.