Reputation: 20456
I am using JQuery's validate plugin to validate a form. Validation occurs and the submitHandler is triggered. But then I get this error (from IE8):
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E) Timestamp: Fri, 20 May 2011 16:30:56 UTC
Message: Object doesn't support this property or method
It works as it should in Firefox- no errors at all. Any ideas why the form.submit() method doesn't work?
$(document).ready(function() {
$.validator.addClassRules('valcount',{digits: true, min: 1});
//Fish Form
$("form[name='fish']").validate({
debug: true,
ignore: ":hidden,[name='']", // do not validate form fields in invisible sections
errorPlacement: function(error, element) {
if ( element.is(":radio") ) {
error.appendTo( element.parent().next().next() );
}else if(element.is(":checkbox") && element.parent().is('li')){
error.insertBefore(element.closest("ul.horiz"));
}else{
error.appendTo(element.parent());
};
},
rules: {
fish_name: {required:true, minlength:5},
care_id: {required: true, digits: true, min: 1},
strain_id: {required: true, digits: true, min: 1},
transgene_id: {digits: true, min: 0}
},
// set this class to error-labels to indicate valid fields
success: function(label) { // set as text for IE
label.html(" ").addClass("checked");
},
submitHandler: function(form){
if(confirm('Are you sure?'))form.submit(); //PROBLEM var has no such method
}
});
});// end $(document).ready(function(){
<form action='http://example.com' method='post' name='fish' id='fish'>
<input name='fish_id' type="hidden" value="39" >
<div><label for='fish_name'>Fish Name</label><input name='fish_name' id='fish_name' type='text' value='110208'></div>
<div><label for='fishnotes'>Notes</label><textarea name='notes' id=fishnotes></textarea></div>
<div><label for='care_id'>Animal Care Protocol</label><select name='care_id' id='care_id'><option value='1' selected="selected">Breeding Colony</option>
</select></div>
<div><label for='strain_id'>Strain</label><select name='strain_id' id='strain_id'><option value='1' selected="selected">AB wt</option>
<option value='2' >Tub wt</option>
<option value='14' >AB/Tub</option>
<option value='15' >AB/Tub deadhead</option>
<option value='16' >Casper</option>
</select></div>
<div><label for='transgene_id'>Transgene</label><select name='transgene_id' id='transgene_id'><option value=0>None</options><option value='1' >Ztag</option>
<option value='2' >KDR-eGFP</option>
<option value='3' >BTIAR-eGFP</option>
<option value='4' >BTIA-eGFP</option>
<option value='5' >BTTP3.1-eGFP</option>
<option value='6' >BTTP6.2-eGFP</option>
<option value='7' >BTIAR-Luc</option>
<option value='8' >BTIA-Luc</option>
<option value='9' >BTTP3.1-Luc</option>
<option value='10' >BTTP6.2-Luc</option>
<option value='11' >Tg(hsp70tolgfp)v28</option>
<option value='16' >blither</option>
</select></div>
<div><input value='Edit' type='submit' ></div>
</form>
Edited: removed submit name and id, added info about FF. Tried with $(form).submit()
instead of form.submit()
. Still no joy.
Upvotes: 1
Views: 4162
Reputation: 20456
It turns out the problem is a conflict between jquery 1.6.x and validate plug-in 1.8.x. When I reverted to jquery 1.5, the issue went away. It's not a very good fix, but hopefully it will save someone some head scratching.
ETA: it appears that validate version 1.8.1, recently released, will fix this problem too. Note that as of May 24th, 1.8.0 is the version hosted at http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.min.js
Upvotes: 0
Reputation: 14859
<input name='submit' id='submitfish' value='Edit' type='submit' >
You can't name a submit button "submit". When you do this and call form.submit() in MSIE, MSIE thinks that you're trying to reference the input object, which "doesn't support this property or method."
Remember that in jQuery, $(this) is a jQuery object and this is the actual DOM element. So
submitHandler: function(form){
The submit handler is passing the form as a DOM element, which is why form.submit() fails here.
Upvotes: 3