# Posting input feilds using link

**URL:** <https://www.ruby-forum.com/t/posting-input-feilds-using-link/72028>\
**Category:** Rails\
**Created:** [October 13, 2006, 6:32pm UTC](https://www.ruby-forum.com/t/posting-input-feilds-using-link/72028 "2006-10-13T18:32:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dipeshbatheja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dipeshbatheja](https://www.ruby-forum.com/u/dipeshbatheja)\
**Post date:** [October 13, 2006, 6:32pm UTC](https://www.ruby-forum.com/t/posting-input-feilds-using-link/72028/1 "2006-10-13T18:32:54Z")

</div>

I have a page that contains a form and some input fields. instead of a  
submit button to post the data back to the server I want to put a link.  
This link when clicked should post the data back to the server. Any  
pointers on how to do this? I have put a link, but it doesn’t post back  
the data from input elements, i also set :post =\> true in link\_to URL  
helper but its not working. Please help

---

<div class="post-metadata">

**Author:** ![dipeshbatheja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dipeshbatheja](https://www.ruby-forum.com/u/dipeshbatheja)\
**Post date:** [October 13, 2006, 7:52pm UTC](https://www.ruby-forum.com/t/posting-input-feilds-using-link/72028/2 "2006-10-13T19:52:00Z")

</div>

Dipesh B. wrote:

> I have a page that contains a form and some input fields. instead of a  
> submit button to post the data back to the server I want to put a link.  
> This link when clicked should post the data back to the server. Any  
> pointers on how to do this? I have put a link, but it doesn’t post back  
> the data from input elements, i also set :post =\> true in link\_to URL  
> helper but its not working. Please help

I think you still want to submit the form using a post, but you want a  
link to do it instead of a button?

In that case, you should still be using a form tag set up with the  
correct action and parameters. Then create a link to submit the form.  
But we’ll use JavaScript to submit it, so we can’t really use link\_to.  
We’ll use link\_to\_function instead.

link\_to\_function “Link Text”, “document.forms[0].submit();”

This will submit the first form on the document (the page). If you have  
more than one form on the page, you’ll have to specify which one.

---

<div class="post-metadata">

**Author:** ![dipeshbatheja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dipeshbatheja](https://www.ruby-forum.com/u/dipeshbatheja)\
**Post date:** [October 14, 2006, 12:07pm UTC](https://www.ruby-forum.com/t/posting-input-feilds-using-link/72028/3 "2006-10-14T12:07:47Z")

</div>

On Oct 13, 2006, at 18:32, Dipesh B. wrote:

> I have a page that contains a form and some input fields. instead  
> of a submit button to post the data back to the server I want to  
> put a link.  
> This link when clicked should post the data back to the server. Any  
> pointers on how to do this?

You need to create a link that executes some javascript which submits  
the form when clicked. $(‘id\_of\_form’).submit() or something to that  
effect is the Javascript you want.

–  
Jakob S. - [http://mentalized.net](http://mentalized.net)

---

<div class="post-metadata">

**Author:** ![dipeshbatheja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dipeshbatheja](https://www.ruby-forum.com/u/dipeshbatheja)\
**Post date:** [October 15, 2006, 7:56am UTC](https://www.ruby-forum.com/t/posting-input-feilds-using-link/72028/4 "2006-10-15T07:56:25Z")

</div>

Kian Wright wrote:

> I think you still want to submit the form using a post, but you want a  
> link to do it instead of a button?
> 
> In that case, you should still be using a form tag set up with the  
> correct action and parameters. Then create a link to submit the form.  
> But we’ll use JavaScript to submit it, so we can’t really use link\_to.  
> We’ll use link\_to\_function instead.
> 
> link\_to\_function “Link Text”, “document.forms[0].submit();”
> 
> This will submit the first form on the document (the page). If you have  
> more than one form on the page, you’ll have to specify which one.

I tried to do this too (taking your suggestion above), but when I make a  
change on the form and click my “Save” link\_to\_function, I get an  
endless “Loading…” and have to restart the server to move anywhere.  
What did I do wrong? I tried it with and without a semi-colon. I only  
have one form on the page, the one that Rails creates from the  
start\_form\_tag, which happens to be lower on the page that the “Save”  
link (but the position shouldn’t matter, right?).

Shauna

---

<div class="post-metadata">

**Author:** ![dipeshbatheja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@dipeshbatheja](https://www.ruby-forum.com/u/dipeshbatheja)\
**Post date:** [October 15, 2006, 10:56am UTC](https://www.ruby-forum.com/t/posting-input-feilds-using-link/72028/5 "2006-10-15T10:56:36Z")

</div>

Shauna wrote:

> I tried to do this too (taking your suggestion above), but when I make a  
> change on the form and click my “Save” link\_to\_function, I get an  
> endless “Loading…” and have to restart the server to move anywhere.  
> What did I do wrong? I tried it with and without a semi-colon. I only  
> have one form on the page, the one that Rails creates from the  
> start\_form\_tag, which happens to be lower on the page that the “Save”  
> link (but the position shouldn’t matter, right?).
> 
> Shauna  
> Check again the form  
> I tried  
> link\_to\_function “Link Text”, “document.forms[0].submit();” too and my  
> start\_form\_tag working properly
