Add text string to a database field when a button is pressed

Hello I am new to ruby and rails (using rails 2). Can some body please
help with the following -
I have a form with a database text field and a series of buttons when a
button is pressed i need a specific string with a time & date stamp
inserting into the on screen text field.
The problem is I don’t want the buttons to post the form, I want the
form to stay open so the user can add additional notes to the same
database text field.
When they have finished then they can hit the create button to insert
into the database their completed text.

How should I do this, code examples would be helpful as I am a newbie to
programming with ruby, rails & javascript.

Thanks in advance

Maybe this can help you:

http://www.railsbrain.com/api/rails-1.2.3/doc/index.html?a=M001753&name=button_to_function

for the javascript function this should do it:

$(‘id_of_your_text_field’).value = ‘your string’

Stijn
http://www.xaop.com

Stijn P. wrote:

Maybe this can help you:

http://www.railsbrain.com/api/rails-1.2.3/doc/index.html?a=M001753&name=button_to_function

for the javascript function this should do it:

$(‘id_of_your_text_field’).value = ‘your string’

Stijn
http://www.xaop.com

Hello Stijn

Thanks for helping,
I have looked at the button_to_function help doc and searched google
etc. and because I am a total newbie it dosen’t make much sence to me
with regards to the implementation of the javascript side of things.

so I have a few questions I was hoping you could help with…

  1. Do I put the javascript in the controller.rb as a ‘def’ or does it
    go in my html.erb file? - do you have a sample source code example
    please :)?

  2. The (‘id_of_your_text_field’) - how do I know what my text field id
    is, for example I have the following extracted from my html.erb file…

so would my id of my text be - ‘action_log’ ?

  1. I was wondering if the user typed some text in the field and then
    clicked the button would the users text be wipped out of the field by
    the button action? - that would be a problem.

thanks

phil

ok Thanks to Stijn and this website…

I was able to work out how to do this, so here is my code which is found
in my new.html.erb file in the views folder…

------------------------ javascript code
function Assign()
{
document.getElementById(“logger_action_log”).value =
document.getElementById(“logger_action_log”).value + “Here is my
output message.”;
}

------------------------- button code

<%= button_to_function “Greeting”, “Assign()” %>


to get the ‘logger_action_log’ id i just looked at my page source code
from the web browser.

so its easy when you know how, hope somebody else finds this useful, let
us know if you do.

Phil