• Post Reply Bookmark Topic Watch Topic
  • New Topic

set focus in textfield in WPS

 
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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!