5

I'm trying to submit a form with javascript. Firefox works fine but IE complains that "Object doesn't support this property or method" on the submit line of this function:

function submitPGV(formName, action)
{
    var gvString = "";

    pgVisibilities.each(function(pair) {
        gvString += pair.key + ":" + pair.value + ",";
    });

    $('pgv_input').value = gvString;

    var form = $(formName);
    form.action = action;
    form.submit();
}

Called here:

<a href="javascript:submitPGV('ProductGroupVisibility','config/productgroupvis/save')">

Here's the form:

<form id="ProductGroupVisibility" action="save" method="post">
    <input type="hidden" name="ows_gv..PGV" id="pgv_input" value=""/>
</form>

Any ideas?

Kenny
  • 1,292
  • 2
  • 15
  • 21

5 Answers5

15

What name does your <input type="submit"> have?

If you called it "submit", you have overridden the form.submit() function, much the same way an input called "foo" would generate a form.foo property. That would explain the behavior.

Tomalak
  • 332,285
  • 67
  • 532
  • 628
5

Try checking the type of the element IE is selecting:

// For getting element with id you must use # 
alert( typeof( $( '#ProductGroupVisibility' )));

It is possible there is something else on the page with that ID that IE selects before the form.

Patrick Hund
  • 19,163
  • 11
  • 66
  • 95
Brian
  • 1,097
  • 11
  • 11
  • Yep. I'm a moron. There was a table with id="productGroupVisibility", Firefox got the form, IE got the table. I was sure I'd already tried changed the id on that table but I wasn't the one at the keyboard so who knows what happened. Thanks heaps mate. – Kenny Nov 05 '08 at 23:18
  • 1
    No problem. Done it myself more than once ;) – Brian Nov 07 '08 at 03:41
  • 2
    Just want to add something that I've just seen that does the same thing. Different case, but same symptoms. Might help someone who stumbles on this answer. "email = $('#UserEmail');" No duplicate id, but IE didn't like that email wasn't officially declared. Changing to: "var email = $('#UserEmail');" Fixes the problem. This is more correct and I guess that's what happens when you get used to programming in more permissive environments. :) – Erik Nedwidek Jun 17 '10 at 15:52
  • This tip is invaluable. Fixed an issue I was having as well. – egid May 11 '12 at 22:33
3

beware of any inputs in the form with name='submit', they break the javascript .submit() functionality!

Ben
  • 31
  • 1
1

What javascript framework are you using? If it's jQuery I think you'll need to add # to your id:

$('#ProductGroupVisibility').submit();
Lance McNearney
  • 9,410
  • 4
  • 49
  • 55
0

Are you sure you have your JavaScript library loaded? (jQuery or Prototype)

It worked for me in IE7 with Prototype.

Try:

alert($('ProductGroupVisibility').id)

See if you get an error.

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
  • You're right actually, it works for me if I put it into a dummy page with only the code listed above. It must be something else about the page. I'll amend my question with more info. Thanks for your help. – Kenny Nov 05 '08 at 22:13