Button_to_function and javascript prompt?

Hello,

I want to ask the users specific question using javascript, and then get
the answer :slight_smile:

<%= button_to_function “My Test”, “prompt(‘Your name is?’)” %>

How can I accomplish this?

I hope someone out there can help me with this, and thanks for your help
:smiley:

On 10/11/07, Jamal S. [email protected] wrote:

Hello,

I want to ask the users specific question using javascript, and then get
the answer :slight_smile:

<%= button_to_function “My Test”, “prompt(‘Your name is?’)” %>

How can I accomplish this?

Well, that will do it. What do you want to do with the answer?

Bob S. wrote:

On 10/11/07, Jamal S. [email protected] wrote:

Hello,

I want to ask the users specific question using javascript, and then get
the answer :slight_smile:

<%= button_to_function “My Test”, “prompt(‘Your name is?’)” %>

How can I accomplish this?

Well, that will do it. What do you want to do with the answer?

I need to catch the answer and add it to the database :smiley:

Thank you very much Bob S. :slight_smile:

On 10/12/07, Jamal S. [email protected] wrote:

How can I accomplish this?

Well, that will do it. What do you want to do with the answer?

I need to catch the answer and add it to the database :smiley:

I suggest you put the results of prompt() into a (js) variable and
then pass it to the server through an Ajax.Request. You can use the
Rails remote_function() helper to write the js for that. Use the :with
option to pass the js variable.

Here’s an example from an app of mine:

<%= javascript_tag %Q{
function x_add_task()
{
var name = prompt(‘Name for new task’, ‘’);
if (name == null) return;
#{remote_function :url => {:action => ‘x_add_task’, :id =>
@obj.id}, :with => “‘name=’ + name” }
}
} %>

Then later:

<%= link_to_function ‘Add Task’, ‘x_add_task()’ %>