Reputation: 1751
I am getting an error of:
TypeError: val.replace is not a function
which is showing the main jquery.js file and cannot seem to trace the problem. I have stripped my code down to the bare essentials to try to isolate the problem, but to no avail. What I have done is to just alert(data)
in the code, but this does not fire. Instead, the form seems to resubmit and in my post tab in firebug, there are 2 submit events. I would be grateful if someone could suggest a way to troubleshoot this.
I would like to add that the validation is working ok, but when it comes to the submit handler, this is where the problem is.
Many thanks
JS
$(function() {
$.validator.setDefaults({
errorClass: 'form_error',
errorElement: 'span',
ignore: ":hidden:not(select)",
errorPlacement: function(error, element) {
error.appendTo(element.siblings('span'));
}
});
$("#USRboxrtv").validate({
rules: {
requested: {
required: true
},
service: {
required: true
},
rtvdept: {
required: true
},
address2: {
required: true
},
box_rtv: {
required: true
}
},
messages: {
requested: {
required: '* required: You must enter your name'
},
rtvdept: {
required: "* required: You must select a department"
},
address2: {
required: "* required: You must select a customer address"
},
service: {
required: "* required: You must select a service level"
},
box_rtv: {
required: "* required: You must enter a box for retrieval"
}
},
submitHandler: function() {
if ($("#USRboxrtv").valid() === true) {
var data = $("#USRboxrtv").serialize();
alert(data);
}
}
});
});
html input
<p>
<input name="submit" class="usersubmit" type="submit" value="Submit" />
<input name="formreset" class="usercancel" type="reset" />
</p>
Upvotes: 0
Views: 189
Reputation: 18109
Okay, so the error message is due to this linevar data = $("#USRboxrtv").serialize();
. I can't tell you what's the reason for it, but if you search this error on google , you will find that the error is in the serialize function. Make sure that the necessary conditions are met for serialize to work. You have not provided the HTML for $("#USRboxrtv")
, so I am not sure where is the error in this case. By the way, are you using the latest version of jquery?
val will either return a string or undefined. I think in your case, val is undefined and that's because you are getting this error.
And as you commented in one of the post :
$(".chosen-select").val('').trigger("chosen:updated");
In this code you are actually assigning an empty value to $(".chosen-select")
which is causing this error.
Upvotes: 1