# Form and popup in RoR

**URL:** <https://www.ruby-forum.com/t/form-and-popup-in-ror/110977>\
**Category:** Rails\
**Created:** [August 1, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/form-and-popup-in-ror/110977 "2007-08-01T17:02:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [August 1, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/form-and-popup-in-ror/110977/1 "2007-08-01T17:02:46Z")

</div>

I have this form helper that I am using that updates a div within the  
form upon completion. The action of the form runs a method that check  
the validaty of a membership number. If it is a good number the number  
is added to a list else it does a popup that indicates that this was not  
a valid membership number. Everything upto that point works fine. Th  
eproblem happens after I hit ‘ok’ on the popup. When I do that I get  
garabage displayed in the div in the form of a try catch block. I think  
that this might be a ruby bug, but does anyone have any ideas of how to  
fix this? Here is some code:

The form tag:

\<%= form\_remote\_tag :update =\> ‘add\_airline\_table’, :url =\> { :action  
=\> ‘add\_airline\_table’, :id =\> @user.id }, :complete =\>  
‘document.getElementById(“account\_num”).value = “”;’ %\>

The alert box:

```
   render :update do |page|
    page.alert 'Invalid Membership Number'
   end

```

The garabage:

try { alert(“Invalid Membership Number”); } catch (e) { alert(‘RJS  
error:\n\n’ + e.toString()); alert(‘alert(“Invalid Membership  
Number”);’); throw e }

Thanks,

~S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [August 1, 2007, 7:01pm UTC](https://www.ruby-forum.com/t/form-and-popup-in-ror/110977/2 "2007-08-01T19:01:57Z")

</div>

It looks to me like your gsrbage is JavaScript. Are you replacing your  
div with a block of JavaScript?

On Aug 1, 11:02 am, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [August 1, 2007, 7:12pm UTC](https://www.ruby-forum.com/t/form-and-popup-in-ror/110977/3 "2007-08-01T19:12:40Z")

</div>

Robert W. wrote:

> It looks to me like your gsrbage is JavaScript. Are you replacing your  
> div with a block of JavaScript?
> 
> On Aug 1, 11:02 am, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Not intentialy. The part of the code that renders the alert is inside my  
add\_airline\_table method. When the method returns and a failure occurs,  
:update is left with nothing to update that div with, but somehow that  
garabage is bleeding through to the :update and displaying. I just don’t  
know how. I have tried several ways to display an empty string in the  
div without success. Whatever is happening is happening at the very last  
instance of updating the div.

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [August 1, 2007, 8:21pm UTC](https://www.ruby-forum.com/t/form-and-popup-in-ror/110977/4 "2007-08-01T20:21:07Z")

</div>

On Aug 1, 2007, at 1:00 PM, Robert W. wrote:

> > is added to a list else it does a popup that indicates that this

Get rid of the :update on the form\_remote\_tag if you are going to  
send back RJS to be evaluated. The RJS can do a page.replace\_html if  
there’s no error.

> > The garabage:
> > 
> > try { alert(“Invalid Membership Number”); } catch (e) { alert(‘RJS  
> > error:\n\n’ + e.toString()); alert(‘alert("Invalid Membership  
> > Number");’); throw e }
> > 
> > Thanks,
> > 
> > ## ~S

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
