• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cursor positioning

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic