• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown

set focus in textfield in WPS

Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a request to set the focus into a portlet's textfield when the page loads. Since we don't have access to the HTML body tag to add 'on_load=document.myform.mytextfield.focus();', I tried doing the following in the endPage(). It doesn't work when the page is first displayed, but if you refresh the page by clicking on the selected tab, it does work. Can anyone explain why it only works sometimes?

PrintWriter writer = response.getWriter();
writer.println("<script for=\"window\" EVENT=\"on_load\" LANGUAGE=\"JavaScript1.2\">");
writer.println("try {");
writer.println("catch(e) { }");

When I view the source of the HTML, it looks like this:

<script for="window" EVENT="on_load" LANGUAGE="JavaScript1.2">
try {
catch(e) { }

FYI, We use WPS 5.1.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic