0

I have one input field and 2 buttons, each button performs a different function. i want one of the buttons to take the value of the input field and add it to a specified Url (as a param) that button should go to.

so if the value inserted in to the box is "dog" then after clicking the button the URL should be "/go_somwhere?value=dog"

can i do it in just html or do i need a ruby method?

i'm using rails.

thanks

Mo.
  • 40,243
  • 37
  • 86
  • 131
  • the other button calls a ruby method that makes a search, that's already in place. im trying to add the new button that will take the value of the input box and add it as a param and go to a new entirely different page. – Mo. Jul 05 '10 at 09:57

2 Answers2

2
<% form_for :item, :url=>{:action=>'go_somwhere'}, :html => { :method=>"get"} do|f| %>

<%= text_field_tag :value, "" %>
<input type="submit" value="Submit" >

<% end %>
Salil
  • 46,566
  • 21
  • 122
  • 156
  • 1
    It will work if its in a form tag. You can access that value from controller's action as `param[:value]`. Your other button that you mentioned should be outside the `form_for` block – Shripad Krishna Jul 05 '10 at 10:26
1

Seems like you would need to do this via javascript on the client side . The button should have a function attached to its click event . This function should read the value from the input box and change the url ( window.locations ) .

NM.
  • 1,909
  • 1
  • 13
  • 21