SmashAndGrab
asked on
Jquery validation questions.
Hi,
I am trying to implement jquery validation on my simple form but have a few questions.
1. How do I get it to carryout submitting the form after validation is true?
My current code is this and it works perfectly:
I just want to be able to run my ajax code if the form validates correctly.
2. How can I improve the validation text so it looks better than just white text? Are there any predefined symbols?
I am trying to implement jquery validation on my simple form but have a few questions.
1. How do I get it to carryout submitting the form after validation is true?
My current code is this and it works perfectly:
$('#submitButton').click(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "pages/add/AddPageUpdate.asp",
data: $(this.form).serialize(),
cache: false,
dataType: "html"
})
.done(function(responseText) {
$('#dialog').popup('show');
})
.fail(function() {
alert("Error");
});
return false;
});
I just want to be able to run my ajax code if the form validates correctly.
2. How can I improve the validation text so it looks better than just white text? Are there any predefined symbols?
Try using the jquery validate plugin it's free and much more advanced and better as to what you are trying to do manually
ASKER
Hi Yes - I have been trying to use the jquery validate but everytime I add the jquery it stops my the ajax part of my jquery from working.
ASKER
I would like it to work.
like this..
Users clicks the submit.
Form validates
if successful run ajax code to submit the form
like this..
Users clicks the submit.
Form validates
if successful run ajax code to submit the form
ASKER
This is the ajax part when the user clicks submit.
I just don't know how to put the validate code in this successfully.
$('#submitButton').click(f unction(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "pages/add/AddPageUpdate.a sp",
data: $(this.form).serialize(),
cache: false,
dataType: "html"
})
.done(function(responseTex t) {
$('#dialog').popup('show') ;
})
.fail(function() {
alert("Error");
});
return false;
});
I just don't know how to put the validate code in this successfully.
$('#submitButton').click(f
e.preventDefault();
$.ajax({
type: "POST",
url: "pages/add/AddPageUpdate.a
data: $(this.form).serialize(),
cache: false,
dataType: "html"
})
.done(function(responseTex
$('#dialog').popup('show')
})
.fail(function() {
alert("Error");
});
return false;
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks.
Here is my attempt:
Existing (working) code (has no validation yet):
Attempt with validation:
My attempt does the validation but the form never gets submitted.
Here is my attempt:
Existing (working) code (has no validation yet):
$('#submitButton').click(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "pages/add/AddPageUpdate.asp",
data: $(this.form).serialize(),
cache: false,
dataType: "html"
})
.done(function(responseText) {
$('#dialog').popup('show');
})
.fail(function() {
alert("Error");
});
return false;
});
Attempt with validation:
$('#submitButton').click(function(e) {
$("#myform").validate({
submitHandler: function(form) {
//form.submit();
// add my code to submit form..
e.preventDefault();
$.ajax({
type: "POST",
url: "pages/add/AddPageUpdate.asp",
data: $(this.form).serialize(),
cache: false,
dataType: "html"
})
.done(function(responseText) {
$('#dialog').popup('show');
})
.fail(function() {
alert("Error");
});
return false;
});
}
});
My attempt does the validation but the form never gets submitted.
Why the data type as HTML
ASKER
I'm not sure, I found the code online.
The ajax part works fine on its own but when I add the validation code it doesn't work - I am assuming the issue is when I add the validation code
The ajax part works fine on its own but when I add the validation code it doesn't work - I am assuming the issue is when I add the validation code