function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rahul2526rahul2526 

showHeader problem

The page below is working absolutely fine...

What I am doing here is that:

 

On pressing the enter key on Text control (Red bolded) i am calling javascript functn which is calling send() from controller class.

 

controller class function is..

 

public PageReference send(){

 //some code

return null;

}

 

 this functn is redirecting on same page...

now other script function setFocusOnLoad() is making Text control to be focussed on page load....

 

when I use showHeader property of <apex:page> to "TRUE"...

all things run fine...

 

but as soon as i disable header i.e make showHeader property to "False"

 

cursor doesnot get focussed to Text control

 

 

<apex:page id="thePage" showHeader="true" sidebar="false" controller="Test">
<script>
function setFocusOnLoad() {

var txt=document.getElementById(text1)
    txt.value=''
  txt.focus()
}

</script>

<script type="text/javascript">
 
function callSend(e){

if(e){
e = e
} else {
e = window.event
}

if(e.which){
var keycode = e.which
} else {
var keycode = e.keyCode
}

if(keycode == 13) {
 

var send=document.getElementById(sendText)
            send.click()
           
            return false
}
else{
return true
}
}


</script>
<apex:form>
    <apex:inputTextarea id="messengerText" value="{!messageText}" readonly="true" cols="100" rows="10" disabled="{!visible2}"/><br>
        <apex:actionPoller action="{!refresh}" reRender="messengerText" interval="5"/>
   
   
 
   
        <apex:outputLabel value="Enter text here"/>
           <apex:inputTextarea id="Text" value="{!text}" cols="70" disabled="{!visible2}" onkeydown="callSend(event)"/><br>
   
           <script> var text1 = '{!$Component.Text}';</script>

   
   
           <apex:commandButton id="send" action="{!send}" value="Send"/>
        <script> var sendText = '{!$Component.send}';</script>
<apex:form>
</apex:page>

 

 

 

Plz tell me the solution of this...

because I don't want the header to be shown on my page and at the same time I want to focus Text control(TextArea) on page load..

 

 

Thank you

 

 

Best Answer chosen by Admin (Salesforce Developers) 
rahul2526rahul2526

Well my problem is solved now....

 

but i think its not a proper way to do it....

 

 

what I have changed in above visualforce page is...

 

I use HTML's <body> tag...

 

i.e

 

<body onload="setFocusOnLoad()">

<apex:inputText />....

.

.

.

.

.

</body>

 

now everytime my page gets load it executes setFocusOnLoad() and sets the focus to my desired Text control...

 

If you get some other possible solution plz let me no...

 

Anyways thanks alot Bob...

 

Thanks for assessment... :smileyhappy:

All Answers

bob_buzzardbob_buzzard

When you use SalesForce standard headers, you can't use onload handlers.  This has cropped up in other threads.

 

If you need to use SF headers and wish to do something onload, the best solution found thus far is to add some JavaScrit to call the focussing function at the bottom of the page.  This does rely on the browser processing components/scripts in order, which may not be the case for all browsers.

rahul2526rahul2526

How can I call a javascript function without using onload handler like setFocusOnLoad  on page load...

 

My requirement is to focus a particular control on loading visual force page without having standard header!!!

 

 

Is this possible???

bob_buzzardbob_buzzard

If you don't have a standard header, you should be able to set an onload handler via the window.onload attribute.

  

rahul2526rahul2526

Well my problem is solved now....

 

but i think its not a proper way to do it....

 

 

what I have changed in above visualforce page is...

 

I use HTML's <body> tag...

 

i.e

 

<body onload="setFocusOnLoad()">

<apex:inputText />....

.

.

.

.

.

</body>

 

now everytime my page gets load it executes setFocusOnLoad() and sets the focus to my desired Text control...

 

If you get some other possible solution plz let me no...

 

Anyways thanks alot Bob...

 

Thanks for assessment... :smileyhappy:

This was selected as the best answer
bob_buzzardbob_buzzard
I'd say that's the correct way to set the focus on load.