我需要帮助,我发现本教程 无需刷新即可验证表单,但问题是我认为这仅适用于文本字段:) 但我使用了 4 个不同的单选按钮,我真的需要这个脚本来处理这些单选按钮!
这是javascript文件:)!
runOnLoad(function(){
$("input#name").select().focus();
});
$(function() {
$('.error').hide();
$(".button").click(function() {
// validate and process form here
$('.error').hide();
var name = $("input#name").val();
if (name == "") {
$("label#name_error").show();
$("input#name").focus();
return false;
}
var email = $("input#email").val();
if (email == "") {
$("label#email_error").show();
$("input#email").focus();
return false;
}
var mobile = $("input#mobile").val();
if (mobile == "") {
$("label#mobile_error").show();
$("input#mobile").focus();
return false;
}
var college = $("input#college").val();
if (college == "") {
$("label#college_error").show();
$("input#college").focus();
return false;
}
var university = $("input#university").val();
if (university == "") {
$("label#university_error").show();
$("input#university").focus();
return false;
}
var level = $("input#level").val();
if (level == "") {
$("label#level_error").show();
$("input#level").focus();
return false;
}
var first_preference = $("input#first_preference").val();
if (first_preference == "") {
$("label#first_preference_error").show();
$("input#first_preference").focus();
return false;
}
var second_preference = $("input#second_preference").val();
if (second_preference == "") {
$("label#second_preference_error").show();
$("input#second_preference").focus();
return false;
}
var third_preference = $("input#third_preference").val();
if (third_preference == "") {
$("label#third_preference_error").show();
$("input#third_preference").focus();
return false;
}
var heard = $("input#heard").val();
if (heard == "") {
$("label#heard_error").show();
$("input#heard").focus();
return false;
}
var applying = $("input#applying").val();
if (applying == "") {
$("label#applying_error").show();
$("input#applying").focus();
return false;
}
var strength = $("input#strength").val();
if (strength == "") {
$("label#strength_error").show();
$("input#strength").focus();
return false;
}
var weakness = $("input#weakness").val();
if (weakness == "") {
$("label#weakness_error").show();
$("input#weakness").focus();
return false;
}
var previousEx = $("input#previousEx").val();
if (previousEx == "") {
$("label#previousEx_error").show();
$("input#previousEx").focus();
return false;
}
var dataString = 'name='+ name + '&email=' + email + '&mobile=' + mobile + '&college=' + college + '&university=' + university + '&level=' + level + '&first_preference=' + first_preference + '&second_preference=' + second_preference + '&third_preference=' + third_preference + '&heard=' + heard + '&applying=' + applying + '&strength=' + strength + '&weakness=' + weakness + '&previousEx=' + previousEx;
$.ajax({
type: "POST",
url: "php/database_sorting.php",
data: dataString,
success: function() {
$('#contact_form').html("<div id='message'></div>");
$('#message').html("<h2>Contact Form Submitted!</h2>")
.append("<p>We will be in touch soon.</p>")
.hide()
.fadeIn(1500, function() {
$('#message').append("<img id='checkmark' src='images/done.png' />");
});
}
});
return false;
});
});