Phil Hand
2008-Mar-21 15:40 UTC
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Stijn Pint
2008-Mar-21 15:59 UTC
Re: add text string to a database field when a button is pre
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phil Hand
2008-Mar-21 19:54 UTC
Re: add text string to a database field when a button is pre
Stijn Pint 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.comHello 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... <!-- <b>Action log</b><br /> <%= f.text_area :action_log %> --> so would my id of my text be - ''action_log'' ? 3. 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phil Hand
2008-Mar-22 09:48 UTC
Re: add text string to a database field when a button is pre
ok Thanks to Stijn and this website... http://www.developnew.com/javascript/textbox.php 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."; } </script> ------------------------- 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---