# How to reset a particular field of form?

**URL:** <https://www.ruby-forum.com/t/how-to-reset-a-particular-field-of-form/124760>\
**Category:** Rails\
**Created:** [January 2, 2008, 10:11am UTC](https://www.ruby-forum.com/t/how-to-reset-a-particular-field-of-form/124760 "2008-01-02T10:11:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 2, 2008, 10:11am UTC](https://www.ruby-forum.com/t/how-to-reset-a-particular-field-of-form/124760/1 "2008-01-02T10:11:12Z")

</div>

In RJS, how can I reset particular field (password) of form, but not  
login?

And also how can I bring cursor to input field when page is loaded? I  
currently have to click in the login field before typing.

Thanks.

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 2, 2008, 2:04pm UTC](https://www.ruby-forum.com/t/how-to-reset-a-particular-field-of-form/124760/2 "2008-01-02T14:04:52Z")

</div>

On Jan 2, 2008, at 3:11 AM, Vapor … wrote:

> In RJS, how can I reset particular field (password) of form, but not  
> login?

If this is an AJAX call, you can use render :update such as

render :update do |page|  
page \<\< “$(‘password\_field\_id’).value = ‘’;”  
page \<\< “$(‘password\_field\_id’).focus();”  
end

If going that route, I’d probably write a javascript function to do  
it and then just call the function

render :update do |page|  
page \<\< “reset\_password();”  
end

or even

page.call ‘reset\_password’

> And also how can I bring cursor to input field when page is loaded? I  
> currently have to click in the login field before typing.

Depending on how you’ve structured your layouts and views, you can  
assign something to the onload event handler of the body tag

Probably, though, you are using layouts and don’t have very easy  
access to the body tag, so you can something like this at the bottom  
of your view

or even render a partial to do it if you might need it on multiple  
pages. You could pass the DOM id in as a local to make it DRY.

I’m sure there are other ways to accomplish your goals, but these can  
at least be jumping off points.

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 2, 2008, 3:10pm UTC](https://www.ruby-forum.com/t/how-to-reset-a-particular-field-of-form/124760/3 "2008-01-02T15:10:29Z")

</div>

WOW  
now this is what I call help 🙂  
thanks a lot
