Forum: Ruby on Rails Odd js behavior in Chrome & Safari

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ken W. (Guest)
on 2008-12-24 12:49
View file has a js function "confirm_result()" in <head> section:

<script type="text/javascript">
    function confirm_action()
    {
      result = confirm("Please select OK or Cancel")
      if (result == true)
        document.write("You selected OK.")
      else
        document.write("You selected Cancel.")
    }
  </script>

The <body> section has

<input type="button" onclick="confirm_action()" value="Submit">

Works just fine in IE7 and FireFox3.

But not in Chrome 1 or Safari 3. In the latter two the confirm box
appears, then a new blank page without the "You selected..."  text. Js
otherwise working fine


Has anyone else encountered this? Bug in Rails? Chrome? Safari?
MaD (Guest)
on 2008-12-24 13:22
(Received via mailing list)
this obviously ain't a bug in rails, as there is not a single line of
ruby/rails-code involved.

why it won't work in chrome or safari i cannot say.
Shandy N. (Guest)
on 2008-12-24 17:45
Ken W. wrote:
> View file has a js function "confirm_result()" in <head> section:
>
> <script type="text/javascript">
>     function confirm_action()
>     {
>       result = confirm("Please select OK or Cancel")
>       if (result == true)
>         document.write("You selected OK.")
>       else
>         document.write("You selected Cancel.")
>     }
>   </script>
>
> The <body> section has
>
> <input type="button" onclick="confirm_action()" value="Submit">
>
> Works just fine in IE7 and FireFox3.
>
> But not in Chrome 1 or Safari 3. In the latter two the confirm box
> appears, then a new blank page without the "You selected..."  text. Js
> otherwise working fine
>
>
> Has anyone else encountered this? Bug in Rails? Chrome? Safari?

Is this written in RoR? If it is the form helper has an :onsubmit
attribute that could be useed to call that JavaScript function and I
would be willing to bet that it would work then. I have had issues with
Safari and Chrome as well but not concerning forms and JavaScript
popups.

A quick search led me to this site which shows how to use the :onsubmit
attribute:

http://railsforum.com/viewtopic.php?id=19539

Good luck,

-S
Ken W. (Guest)
on 2008-12-25 08:45
Tried the "onsubmit".

Didn't help.

I think it's a bug in both Google Chrome and Safari.

Anyone else encountered the same thing?
Rimantas L. (Guest)
on 2008-12-25 14:28
(Received via mailing list)
> Tried the "onsubmit".
>
> Didn't help.
>
> I think it's a bug in both Google Chrome and Safari.
>
> Anyone else encountered the same thing?

https://bugs.webkit.org/show_bug.cgi?id=8961
https://bugs.webkit.org/show_bug.cgi?id=14709

Are you sure you want to use document.write instead of some DOM
manipulation?

Regards,
Rimantas
--
http://rimantas.com/
chauzer (Guest)
on 2009-02-14 12:13
(Received via mailing list)
I ran into this same issue, it has nothing to do with Rails.  This
looks to be an issue with the way WebKit (used by Safari and Chrome)
handles javascript and form submits.  Looks like if there is a onclick
on a submit button, data from the form is not submitted when the page
is posted.

On Dec 24 2008, 2:49 am, Ken W. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.