text box value in the confirmation popup

kinda hung here I have this and I am getting js in the popup.

<%= @deposit = javascript_tag “$(‘funding_transaction_deposit’).innerHTML” %>

<%= submit_tag ‘Create’, :confirm => “Are you sure you would like #{@deposit} dibits deposited?” %>

I want to display the value of a text box in the confirmation popup

anybody?

I have a text box in a form I would like the value of displayed in the confirmation box.

kinda hung here I have this and I am getting js in the popup.

<%= @deposit = javascript_tag “$(‘funding_transaction_deposit’).innerHTML” %>

<%= submit_tag ‘Create’, :confirm => “Are you sure you would like #{@deposit} dibits deposited?” %>

What if you do this: <%= submit_tag ‘Create’, :confirm => “Are you sure you would like " + $(‘funding_transaction_deposit’).innerHTML() + " dibits deposited?” %>

compile error
/Users/chabgood/web_apps_svn_working/dibspace_unfuddle/r2/app/views/funding_transactions/_form.rhtml:15: syntax error, unexpected $undefined
... you sure you would like " + $('funding_transaction_deposit'...

> kinda hung here I have this and I am getting js in the popup.

> <%= @deposit = javascript_tag "$('funding_transaction_deposit').innerHTML" > %> > <p> > <%= submit_tag 'Create', :confirm => "Are you sure you would like > #{@deposit} dibits deposited?" %> > </p>

What if you do this: <%= submit_tag 'Create', :confirm => "Are you sure you would like " + $('funding_transaction_deposit').innerHTML() + " dibits deposited?" %>

Submit tag is probably going to escape any attempt at including actual javascript in the confirm text (I'd consider it a bug if it didn't). You're probably going to need to craft the button's onclick by hand (You could look at the autogenerated javascript and then replace the confirm message with something similar to what David suggested.

Fred

Is there no way to assign the val to a var and just putting it in the string?

I had this originally:

%= @deposit = javascript_tag “$(‘funding_transaction_deposit’).innerHTML” %>

<%= submit_tag ‘Create’, :confirm => “Are you sure you would like #{@deposit} dibits deposited?” %>

not the way submit_tag generates it's javascript.

Ok I am doing it the manual way, how do I get the value to show up? Are the quotes correct?

The simplest way to do the return true/false stuff is:

<form action="foo" method="post" onsubmit="return confirm('Are you sure?');"> ...

The return false (which happens if the confirm is cancelled) stops the form submission directly. I imagine you could do the same with your onclick event on the button, but putting it in the form submission makes it pretty foolproof, since the button might not be clicked (someone types Enter and the form submits without a click).

Walter

Actually what I posted is what rails produces, I copied the javascript from the page source. I was more interested how to get the div id value into the string, is it a quote issue?

Actually what I posted is what rails produces, I copied the javascript from the page source. I was more interested how to get the div id value into the string, is it a quote issue?

Oh, sorry I missed that. If you have Prototype in your page, then the syntax to get a form field's value is

$F('theIdOfTheField')

The quotes look fine. If you don't have Prototype, then the syntax would be something like

getElementById('theIdOfTheField').value

Walter

ya is this correct?

That looks right, does it work?

Walter

No I am not getting a prompt.

For what? unless you quote the relevant part of the original email and put your responses inline anyone who happens to stumble into the middle of your issue is unlikely to be able to help.

Best Wishes, Peter

What do you see in the Firebug console or the Safari Web Inspector? You're debugging JavaScript now, so use the tools that let you do that.

Walter