# In-page popup not supporting DOM structure/properties

**URL:** <https://www.ruby-forum.com/t/in-page-popup-not-supporting-dom-structure-properties/138355>\
**Category:** Rails\
**Created:** [May 22, 2008, 8:37am UTC](https://www.ruby-forum.com/t/in-page-popup-not-supporting-dom-structure-properties/138355 "2008-05-22T08:37:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![adhiraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@adhiraj](https://www.ruby-forum.com/u/adhiraj)\
**Post date:** [May 22, 2008, 8:37am UTC](https://www.ruby-forum.com/t/in-page-popup-not-supporting-dom-structure-properties/138355/1 "2008-05-22T08:37:23Z")

</div>

In my current app, I have an in-page popup(those semi-transparent ones  
like you find on Facebook) for login, which has only two fields: login  
and password.  
I am not able to set focus in the login field.

document.getElementById(‘element’).focus(); doesn’t seem to work.  
document.getElementById(‘element’) returns “null”.

I have a link for ‘Login’ on the ‘Home Page’. When user clicks on the  
Login link, an in-page pop is rendered on the same page, so you can see  
the ‘Home Page’ in the background, but focus is on the ‘Login popup’.  
I think that’s because we have two layers of documents, one the ‘Home  
Page’ and second the ‘Login’ popup’. So something wrong with the DOM  
structure. Not sure…

Does anyone know how to handle this situation?

Thanks in advance

Adhiraj

---

<div class="post-metadata">

**Author:** ![adhiraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@adhiraj](https://www.ruby-forum.com/u/adhiraj)\
**Post date:** [May 22, 2008, 11:16am UTC](https://www.ruby-forum.com/t/in-page-popup-not-supporting-dom-structure-properties/138355/2 "2008-05-22T11:16:32Z")

</div>

On 22 May 2008, at 07:37, Adhiraj Rankhambe wrote:

> Login link, an in-page pop is rendered on the same page, so you can  
> see  
> the ‘Home Page’ in the background, but focus is on the ‘Login popup’.  
> I think that’s because we have two layers of documents, one the ‘Home  
> Page’ and second the ‘Login’ popup’. So something wrong with the DOM  
> structure. Not sure…

It shouldn’t require anything special, assuming all your markup is  
nice and tidy. You’re also asking for trouble if you’ve got multiple  
page elements with the same id (which can easily happen by accident)

Fred

---

<div class="post-metadata">

**Author:** ![adhiraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@adhiraj](https://www.ruby-forum.com/u/adhiraj)\
**Post date:** [May 22, 2008, 3:59pm UTC](https://www.ruby-forum.com/t/in-page-popup-not-supporting-dom-structure-properties/138355/3 "2008-05-22T15:59:15Z")

</div>

I am actually using this statement:

document.getElementById(‘login’).focus();  
But it doesn’t seem to work.  
There is no other element by the same id. I did check it.

But doesn’t seem to work.

Adhiraj

---

<div class="post-metadata">

**Author:** ![adhiraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@adhiraj](https://www.ruby-forum.com/u/adhiraj)\
**Post date:** [June 18, 2008, 9:29am UTC](https://www.ruby-forum.com/t/in-page-popup-not-supporting-dom-structure-properties/138355/4 "2008-06-18T09:29:18Z")

</div>

Worked it out…

I solved it out by using:

render :update do |page|  
page.call(function, \*arguments, &block)  
end

[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html)

Cheers…

Adhiraj

---

<div class="post-metadata">

**Author:** ![adhiraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@adhiraj](https://www.ruby-forum.com/u/adhiraj)\
**Post date:** [June 18, 2008, 11:15am UTC](https://www.ruby-forum.com/t/in-page-popup-not-supporting-dom-structure-properties/138355/5 "2008-06-18T11:15:06Z")

</div>

Adhiraj Rankhambe wrote:

> In my current app, I have an in-page popup(those semi-transparent ones  
> like you find on Facebook) for login, which has only two fields: login  
> and password.  
> I am not able to set focus in the login field.
> 
> document.getElementById(‘element’).focus(); doesn’t seem to work.  
> document.getElementById(‘element’) returns “null”.
> 
> I have a link for ‘Login’ on the ‘Home Page’. When user clicks on the  
> Login link, an in-page pop is rendered on the same page, so you can see  
> the ‘Home Page’ in the background, but focus is on the ‘Login popup’.  
> I think that’s because we have two layers of documents, one the ‘Home  
> Page’ and second the ‘Login’ popup’. So something wrong with the DOM  
> structure. Not sure…
> 
> Does anyone know how to handle this situation?
> 
> Thanks in advance
> 
> Adhiraj

Hi,  
in javascript function use like  
“document.forms[0].elements[0].focus()”
