Topic: Changing value of ONSUBMIT for AJAX works in Firefox... not in IE

I'm trying the following to allow one form to submit alternately to two different actions:

    if (id == 0)
    {
        $('stack_quick_form').action = '/stack/new'
        $('stack_quick_form').attributes["onsubmit"].value="new Ajax.Updater('stack_list', '/stack/new', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;";
        $('stack_quick_form').stack_id.value = 0;
    }
    else
    {
        $('stack_quick_form').action = '/stack/push'
        $('stack_quick_form').attributes["onsubmit"].value="new Ajax.Updater('stack_" + id  + "', '/stack/push', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;";
        $('stack_quick_form').stack_id.value = id;
        $('stack_menu_' + id).style.display='block';
    }

Here's the form that gets updated:
<%= form_remote_tag :url => {:action => 'new'}, :update => 'stack_list',
                    :html => {:id => 'stack_quick_form'} %>
   <input name='stack_id' type='hidden' id='stack_id' value=0>
   <input name='name' id='name' value='Enter the name here' class='text_box' >
   <input type=submit>
</form>

Now when I click on a link like this:

Everything works in firefox just fine, and the ajax request is sent and the appropriate page component updated.  However, if I do it with Internet Explorer... it does a normal (non-ajax) post and returns that subsection as the whole page.

The only thing I can think is that it doesn't like having the onsubmit value messed with, but I can't figure out how to see what it's being set to...  anyway the conditional post (to 'new' or 'push') still works, it just doesn't do it the AJAX way, which is really annoying.

Has anyone else run into this?  God, I hope so cause I have no idea where to start.

Re: Changing value of ONSUBMIT for AJAX works in Firefox... not in IE

How about just have the form onsubmit call your own javascript function? This way you can do the condition there instead of trying to change the onsubmit.

Railscasts - Free Ruby on Rails Screencasts

Re: Changing value of ONSUBMIT for AJAX works in Firefox... not in IE

Well I've given that a shot and now it does the non-AJAX post in both situations... at least it's consistent smile

I'll have to take a look there must be something I'm doing wrong:

<script>
function expand_stack(id)
{
    var stack_id_list = new Array(<%= stack_array_helper -%>);
   
    // Set a global for current stack
    current_stack_id = id;
   
    for (var i = 0; i < stack_id_list.length; i++)
    {
        $('stack_menu_' + stack_id_list[i]).style.display='none';
        $('stack_title_' + stack_id_list[i]).removeClassName('selected');
    }
   
    if (id == 0)
    {
        $('stack_quick_form').action = '<%= url_for(:action => "new") -%>'
    }
    else
    {
        $('stack_quick_form').action = '<%= url_for(:action => "push") -%>'
        $('stack_menu_' + id).style.display='block';
    }
   
    $('stack_title_' + id).addClassName('selected');
}

function ajax_submit()
{
    $('stack_quick_form').stack_id.value = window.current_stack_id;
    if (window.current_stack_id > 0)
    {
        var myAjax = new Ajax.Updater('stack_' + window.current_stack_id, '/stack/push',
                {
                    asynchronous:true,
                    evalScripts:true,
                    parameters:Form.serialize(this)
                });
    }
    else
    {
        var myAjax = new Ajax.Updater('stack_list', '/stack/new',
                {
                    asynchronous:true,
                    evalScripts:true,
                    parameters:Form.serialize(this)
                });
    }
}
</script>

<form action='/stack/new' id='stack_quick_form' onsubmit='ajax_submit(); return false;'>
  <input name='stack_id' type='hidden' id='stack_id' value=0>
  <input name='name' id='name'  value='Set a new goal here'  class='text_box' >
  <input type="image" src='/images/arrow.gif' />
</form>

Re: Changing value of ONSUBMIT for AJAX works in Firefox... not in IE

Ok this is me being stupid...

parameters:Form.serialize(this)

changed to:
parameters:Form.serialize($('stack_quick_form'))

I guess I can't turn a javascript function, or whatever
"this" is at that moment into a form with the parameters
i want tongue