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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

position of cursor after on click event

Status
Not open for further replies.

mak2112

IS-IT--Management
Aug 8, 2001
46
I have created a program that takes information from a specifc page, and re-generates the page with the updated information if a check mark has been entered in a check box. this being said, i would like the focus of the cursor to go back to the last check box marked, after the page refresh's itself. any ideas. it is using an onclick to submit the changes.
 
At first you would think you could just update a variable "lastChecked" whenever a checkbox is checked, but since users have the ability to uncheck checkboxes, you'd have to keep a history of what boxes they've checked. That way, if they uncheck the last box they checked, the "lastChecked" variable could be updated to the last box they checked that is still checked. The psuedo code would look like this:

declare an array to keep the history of boxes checked
On click event of checkbox
if box is being checked
append the id of the box to the history array
else if box is being unchecked
loop through the history array
remove the item from the array if found

On submit event of the form
set hidden form field to last history array item

You weren't specific, so I'm guessing you're using a separate page to process the form. When the form is done being processed, redirect back to the form - adding the id of the box last checked to the url.

On load of the form
extract the id from the url
find the checkbox that matches the id extracted
either loop through the form elements or
use the getElementByID() method
set the focus on the box Adam
 
actually i can parse the informtion of the last box into the source, that is not the problem. the problem is the code once the page is redirected.

the user checks the box and clicks update, that is fine, and i can bring that variable back, however I just cannot get the screen or mouse to move down to that after refreshing. it goes back to the top of the page. i am looking for help with the code to take me back to the same part of the page i was on.

code i thought would work is

form.cust_("v_variablea").focus()

where cust_ is the name of the variable and v_variablea is the value of that variable.
 
Well, you can't move the mouse, and using focus() will only scroll the field into view (if it's visible), it won't scroll the page to exactly where it was before. I'd probably pass document.body.scrollTop as the variable and use scrollTo(0,previousScrollTop) to get the page to where it was before.

If updating the page is going to move a lot of things around on the page, maybe focus() is the way to go. If each checkbox has a unique name, use:
document.formName["checkboxName"].focus()
If each checkbox has the same name, uniquely identify the boxes using id="c1", id="c2", and so on. Then use:
document.getElementByID("checkboxID").focus() Adam
 
Thanks guys, i will try this tomorrow as soon as i get in. thanks for the posts, and i will reply.
 
hey,

i tried the new code this morning
document.getElementByID("checkboxID").focus()

and for some reason i keep getting an error. i believe the error is caused by the method any other suggestions on what to use besides .focus?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top