# Setfocus to a field in view

**URL:** <https://www.ruby-forum.com/t/setfocus-to-a-field-in-view/138640>\
**Category:** Rails\
**Created:** [May 26, 2008, 10:10am UTC](https://www.ruby-forum.com/t/setfocus-to-a-field-in-view/138640 "2008-05-26T10:10:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 26, 2008, 10:10am UTC](https://www.ruby-forum.com/t/setfocus-to-a-field-in-view/138640/1 "2008-05-26T10:10:37Z")

</div>

Hi  
I have a div “reason\_for\_transfer\_search\_sd” like

\<%= render :partial =\> "service\_desk\_part/on\_action\_transfer\_reason\_sd\_search", :locals =\> { :sd\_ticket=\>sd\_ticket } %\> 

And in on\_action\_transfer\_reason\_sd\_search  
\<%= text\_area\_tag “transfer\_reason”, nil, :size =\> “50x1” %\>  
\<%= link\_to\_remote “Submit”,  
{:with =\> “‘transfer\_reason=’ + $(‘transfer\_reason’).value”,  
:url =\> { :controller =\> :service\_desk,:action =\>  
:edit\_service\_desk\_status\_after\_transfer\_from\_search\_sd,  
:sd\_id =\> sd\_ticket.id,  
} },  
%\>

So to focus cursor to this textarea I used  
\<%= set\_focus\_to\_id ‘transfer\_reason’ %\> just below that and it is  
working properly. And in appliation helper  
def set\_focus\_to\_id(id)  
javascript\_tag("$(’#{id}’).focus()");  
end  
But my problem is i am replacing the same div from the controller  
after processing using rjs…But this time cursor focus does not goes to  
text area.What might be the reason?

Thanks in advance  
Sijo
