• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javascript Function Not Getting Called after setFocus()

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am using java-script in my application and i am in the middle of a bizarre situation.

I have used the below code in my page.


The problem that I am facing is after the setFocus() function is called the other function rendersection() is not called. But when i remove the setFocus() and then try, then the rendersection() is called. As seen in the above code i have also tried giving the rendersection() before the setFocus(). still it does not work. Does anyone know if i am missing anything here?

Also, when i tried to change the setFocus() to something different like putFocus or getFocus the function is called but the focus is not set to the desired field
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a lot of things to comment on here, but I'll just hit on a few:

First:

vikram solanki wrote:
renderSection('false');


If the function is expecting a boolean, why are you passing a string? Did you realize that if you use the string argument in a if clause that 'string" is truthy?

Be sure to be consistent with data typing. Use false not "false" for boolean values.

The most likely cause of failure is:

document.getElementById("{!$component.thePageBlock.state}").focus()


That's one bizarre id value and I suspect it's not real. This should cause an exception when the focus() method is attempted on an undefined reference.

Do you have the JavaScript console open so you can see any script errors?
 
whippersnapper
Posts: 1843
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Believe it or not, that id appears to be valid.

http://jsfiddle.net/QCwLd/2/
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Matola wrote:Believe it or not, that id appears to be valid.


Oh, yes, it is technically legal (though insane) -- sorry for not being clear -- but to me it looks like server-side markup and so I'm not convinced that it's really the right id and the method is actually finding anything.
 
vikram solanki
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry... I should have a bit more clearer. The js script i have shared here is used in a tool(or a platform) so the bizarre id. The id means that I am referring to an object(element) inside a page block with the id 'thePageBlock' and an element with the id 'state'. The setFocus() function works fine. It sets the focus to the correct element.

As for the error, I am not getting any in my console.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So have you 100% verified that the call to document.getElementById("{!$component.thePageBlock.state}") is returning an element?
reply
    Bookmark Topic Watch Topic
  • New Topic