この最も可能性の高い単純な質問で申し訳ありません。
フォーム (以下のコード) の送信時にスクリプトを実行していますが、コードが実行される前にフォーム (電子メールである必要があるテキスト ボックスが 1 つ含まれています) を検証したいと思います。
以下のスクリプトは、フォーム データがカラーボックス ライトボックス スクリプトに確実に渡されるようにするために、ここから取得したものです。しかし、フォームが検証された場合にのみこれを実行したいと思います。これを電子メール検証スクリプトと組み合わせる方法がわかりません。ヘルプ!現時点では、電子メール (dreamweaver の) を検証するスクリプトがあり、これが実行されています。このコマンドは、検証されなくても実行され、編集方法がわからないため、編集できません。
$(document).ready(function() {
$("input#SearchButton").colorbox({href: function(){
var url = $(this).parents('form').attr('action');
var ser = $(this).parents('form').serialize(); //alert(url+'?'+ser);
return url+'?'+ser;
}, innerWidth:"1280", innerHeight:"884px", iframe:true, scrolling:false});
});
次に、これを使用してフォームを検証しています。
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} }} else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }
ありがとう!!!!
トラの HTML は次のとおりです。
<input name="submit" type="image" onclick="MM_validateForm('email','','RisEmail');return document.MM_returnValue" src="images/go-button.gif" alt="Go! Get quote now!" align="top" : id="SearchButton"/>
一言で言えば、3番目のコードスニペットでもhtmlによって呼び出される2番目のスニペットのコードを使用してフォームが検証される場合、最初のスニペットのコードをティガーしたいのですが、そうでない場合はそうではありません。