I have two forms in a user control, posting an email with jQuery and Ajax. Unfortunately, our cms using .NET Web Forms and master pages, which makes name attribute changing. This makes it difficult to use jquery validate, since it is based on the attribute name. Do you have any suggestions how I can solve this ?
Code
$(function () {
$("#tbSendComment").click(function (e) {
$('#formComment').validate({
rules: {
ctl00$mainPlaceHolder$ctl02$tbCommentSubject: "required",
ctl00$mainPlaceHolder$ctl02$tbCommentMessage: "required",
ctl00$mainPlaceHolder$ctl02$tbCommentName: "required",
ctl00$mainPlaceHolder$ctl02$tbCommentEmail: {
required: true,
email: true
}
},
submitHandler: function (form) {
var obj = {};
var Uri = '<%: Uri %>';
var Title = '<%: Title %>';
obj.subject = $("#tbCommentSubject").val();
obj.message = $("#tbCommentMessage").val();
obj.name = $("#tbCommentName").val();
obj.fromEmail = $("#tbCommentEmail").val();
obj.cc = $("#cbSendMeCoppyComment").prop('checked');
obj.title = Title;
obj.uri = Uri;
var jsonData = JSON.stringify(obj);
$.ajax({
type: "POST",
url: "/leaveacomment",
data: jsonData,
success: function successFunc(data) {
etc
etc