# Submitting a form without clicking the submit button?

**URL:** <https://www.ruby-forum.com/t/submitting-a-form-without-clicking-the-submit-button/108054>\
**Category:** Rails\
**Created:** [June 28, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/submitting-a-form-without-clicking-the-submit-button/108054 "2007-06-28T19:50:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [June 28, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/submitting-a-form-without-clicking-the-submit-button/108054/1 "2007-06-28T19:50:39Z")

</div>

I’m using AJAX with 2 select pulldowns. When you select an item in the  
first pulldown, it dynamically populates the second pulldown. However,  
I need to value of the first select pulldown to know how to populate the  
second pulldown. When I select an element in the first pulldown, and  
submit via clicking the submit button, it posts the value as needed and  
sends in in the params hash. I’m trying to get the selected value to  
return via the params hash but to do so “onchange” instead of by  
clicking the submit button. Does anyone know how to submit a form  
without having the user click the button?

---

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [June 28, 2007, 8:34pm UTC](https://www.ruby-forum.com/t/submitting-a-form-without-clicking-the-submit-button/108054/2 "2007-06-28T20:34:19Z")

</div>

Hi Daniel,

Daniel L. wrote:

> I’m using AJAX with 2 select pulldowns. When you select an item in the  
> first pulldown, it dynamically populates the second pulldown. However,  
> I need to value of the first select pulldown to know how to populate the  
> second pulldown. When I select an element in the first pulldown, and  
> submit via clicking the submit button, it posts the value as needed and  
> sends in in the params hash. I’m trying to get the selected value to  
> return via the params hash but to do so “onchange” instead of by  
> clicking the submit button. Does anyone know how to submit a form  
> without having the user click the button?

You don’t submit the form. Use observe\_field to submit the change to  
the  
first pulldown, then RJS to render the second. There’s been quite a bit  
of  
discussion here about how to use observe\_field with select boxes and I’m  
sure you can Google it up.

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [June 28, 2007, 8:54pm UTC](https://www.ruby-forum.com/t/submitting-a-form-without-clicking-the-submit-button/108054/3 "2007-06-28T20:54:26Z")

</div>

Thanks Bill. I just figured it out a few minutes ago. I wasn’t sure if  
the method I chose was appropriate, but it looks like it is. Again,  
thanks for your help!

Bill W. wrote:

> Hi Daniel,
> 
> Daniel L. wrote:
> 
> > I’m using AJAX with 2 select pulldowns. When you select an item in the  
> > first pulldown, it dynamically populates the second pulldown. However,  
> > I need to value of the first select pulldown to know how to populate the  
> > second pulldown. When I select an element in the first pulldown, and  
> > submit via clicking the submit button, it posts the value as needed and  
> > sends in in the params hash. I’m trying to get the selected value to  
> > return via the params hash but to do so “onchange” instead of by  
> > clicking the submit button. Does anyone know how to submit a form  
> > without having the user click the button?
> 
> You don’t submit the form. Use observe\_field to submit the change to  
> the  
> first pulldown, then RJS to render the second. There’s been quite a bit  
> of  
> discussion here about how to use observe\_field with select boxes and I’m  
> sure you can Google it up.
> 
> hth,  
> Bill

---

<div class="post-metadata">

**Author:** ![liberte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@liberte](https://www.ruby-forum.com/u/liberte)\
**Post date:** [June 28, 2007, 10:13pm UTC](https://www.ruby-forum.com/t/submitting-a-form-without-clicking-the-submit-button/108054/4 "2007-06-28T22:13:45Z")

</div>

Daniel L. wrote:

> Thanks Bill. I just figured it out a few minutes ago. I wasn’t sure if  
> the method I chose was appropriate, but it looks like it is. Again,  
> thanks for your help!

You’re welcome!

Bill
