Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

set focus in textfield in WPS  RSS feed

 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • 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("document.myform.mytextfield.focus();");
writer.println("}");
writer.println("catch(e) { }");
writer.println("</script>");


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

<script for="window" EVENT="on_load" LANGUAGE="JavaScript1.2">
try {
document.myform.mytextfield.focus();
}
catch(e) { }
</script>

FYI, We use WPS 5.1.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!