$(document).ready(function(){ $("#contact_form").submit(function() { var result = true; $(".errMsg").hide(); var name = $('#contact_form [name=name]').val(); if (name.length == 0) { $("#name_err").html("お名前を入力してください。
").fadeIn(); result = false; } var name_kana = $('#contact_form [name=name_kana]').val(); if (name_kana.length == 0) { $("#name_kana_err").html("ふりがなを入力してください。
").fadeIn(); result = false; } var e_mail = $('#contact_form [name=e_mail]').val(); var e_mail_confirm = $('#contact_form [name=e_mail_confirm]').val(); if (!e_mail.match(/.+@.+\..+/)) { $("#e_mail_err").html("E-MAILの形式が正しくありません。
").fadeIn(); result = false; } if (e_mail.length == 0) { $("#e_mail_err").html("E-MAILを入力してください。
").fadeIn(); result = false; } if (e_mail != e_mail_confirm) { $("#e_mail_conf_err").html("E-MAILと同じ値を入力してください。
").fadeIn(); result = false; } if (e_mail_confirm.length == 0) { $("#e_mail_conf_err").html("E-MAIL(確認用)を入力してください。
").fadeIn(); result = false; } if (!checkRequire("checkbox", "form_2")) { $("#form_2_err").html("選択してください。
").fadeIn(); result = false; } if (!checkRequire("radio", "form_3")) { $("#form_3_err").html("選択してください。
").fadeIn(); result = false; } // その他が選択されていた場合、テキストが入力されているかチェック if (!checkOtherRequire("radio", "3")) { $("#form_3_err").html("その他を入力してください。
").fadeIn(); result = false; } location.href='#contact_us'; return result; }); function checkRequire(type, form_name) { if (type == 'text' || type == 'textarea') { if (!$('#contact_form [name=' + form_name + ']').val()) { return false; } } else if (type == 'radio') { if (!$('input:radio[name=' + form_name + ']:checked').val()) { return false; } } else if (type == 'checkbox') { chk_result = false; $('.chk_' + form_name).each(function(){ if ($(this).attr('checked') == 'checked') { chk_result = true; } }); return chk_result; } else if (type == 'select') { if (!$('#contact_form [name=' + form_name + ']').val()) { return false; } } return true; } function checkOtherRequire(type, form_no) { if (type == 'checkbox' || type == 'radio') { if ($("#form_" + form_no + "_other").attr('checked') == 'checked') { if (!$('#contact_form [name=form_' + form_no + '_other_text]').val()) { return false; } } } return true; } });