+ Start a Discussion

Unable to set focus on visualforce page

Hi All,

I am a starter on visualforce development and I am having a problem setting focus using jQuery on visualforce page.

here is part of the code for the visualforce:

<apex:form id="dataform">
    <apex:pageBlock title="LABOR AND QUANTITY BOOKING" mode="edit" id="pageblock">
        <apex:pageBlockSection columns="1" id="section">
            <apex:inputText value="{!operator}" label="Operator" id="operator"/>
            <apex:inputText value="{!workOrderNumber}" label="Work Order" id="wo"/>
      <apex:pageBlockButtons id="buttons" location="bottom">
            <apex:commandButton value="Save" action="{!save}" id="save" />
            <apex:commandButton value="Cancel" action="{!cancel}"/>

What I am trying to do is to set focus on the second field(work order)when page loads, and here is the jQuey
<apex:includeScript value="{!URLFOR($Resource.jquery)}"  />
<script type="text/javascript">

But the code is not working. the focus will always be on the first field. I tried to do an alert after the set focus statement, and it looks like the focus is set to the second field when it alerts, but for some reason, it is set back to the first field after the alert. Have any ideas?
Best Answer chosen by CharlesDou