TypeError: f[s] is not a function for jquery form submission

Hierophect picture Hierophect · Oct 31, 2012 · Viewed 13.9k times · Source

I'm trying to get a form to submit in a roundabout way, since I need it to append new inputs before it submits. Since putting appends in the actual $(form).submit() function will not gather them for post, I've added an html button to call a submitCheck(), and then submit the actual function.

function init() {
  $("#submit").click(submitCheck);
  //and lots of other stuff
}

function submitCheck() {
    //go through fabric canvases, save xml to input.
    for (var i=1; i<probNum; i++) {
        var csvg = gcanvas[i].toSVG();
        $('#output').append("<input type='hidden' name='svg"+probNum+"' value='"+csvg+"'></input>");
    }
    //make sure a topic was selected. If not cancel submission and don't do anything.
    if ($("#topic").val() == '-1') 
    {
        $('#error').html("You must select a valid topic");
    } else {
        //submit the form
        alert('should submit now');
        $("form:first").submit();
    }
}

But... it fails, throwing the type error:

TypeError: f[s] is not a function

I've found no documentation on this particular error. Any ideas?

Answer

Esailija picture Esailija · Oct 31, 2012

You have some input with name="submit" in your form, which overrides the native form.submit (programmatically submits the form) method that is being called internally in jQuery. You need to change that to some other name.

See the Additional Notes paragraph in the documentation.

You can also use DOMLint to see other possible conflict issues.