File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Cursor positioning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Cursor positioning" Watch "Cursor positioning" New topic
Author

Cursor positioning

Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
(This may be a HTML or JavaScript issue)
I have a JSP/Servlet web application that uses many HTML forms to capture various input requests. I would like to highlight and position the cursor on a specific text field if the input supplied is in error.
I have managed to get the highlighting bit working by setting error-type request attributes in the servlets which are interpreted as such by the respective JSP code. But how can I position the cursor on the same highlighted text field? (without using JavaScript, that is)
Any ideas very welcome.
Thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Have you tried to use the TABINDEX attribute in your form components. In theory a value of "1" should make a form element get the focus, but I have not tested it.
Bill
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi William,
tabindex is HTML thing right and so we can probably manipulate that property of any form object using JavaScript only, right?
Mark is asking for changes 'not using javascript' so does your response solve his problem? can you please explain to me if i didn't understand your response and scrwed up myself?
i remember, my friend was required to implement the same thing and what he did was-
1. he embedded the error field information in the request (as Mark is doing)
2. in JSP, upon rendering the form he checked if the any error field is there in the request and then he displayed the field name in red color (though he didn't have a focus on the field i guess but thats similar, right)

thank you.
maulin
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
Bill
Thanks for your help. The TABINDEX attribute can be applied to several form-related entities, such as <SELECT>, <INPUT>, <A>, <BUTTON> and <TEXTAREA>.
It is a means of arranging the keyboard tab sequence of your form fields, starting from "1". Unfortunately, after the JSP page has been rendered, you must still hit the tab key to gain focus on the "1" field. In fact, it seems you need to press the tab key twice, as the first tab stop appears to default to the address bar of the browser.
Still, it was better than nothing at all, or having to fill the page up with excessive JavaScript
Maulin, I don't think Bill was referring to JavaScript at all. TABINDEX is purely a HTML attribute that can be used with certain other HTML tags.
It doesn't gain immediate focus on the error field as I hoped it might, but it has introduced me to a neat way of ordering my tabstops. Especially if your JSP page contains recurring lists of data, you can define an integer to control your TABINDEX values, and use it in a JSP expression as you loop through your lists.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cursor positioning