This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cursor positioning

 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic