在ASP程序中我们经常会要求用户填写一个表单然后直接点发送按钮发送给我们今天这个程序就是限制表单内容然后再发送给我们
只是一个简单的实例希望对大家编程有用
HTML表单
<form action=actionasp method=post name=myform>
Name and Surname: <br/>
<input type=text name=nameandsurname size=> <br/>
Email: <br/>
<input type=text name=email size=> <br/>
Age: <br/>
<input type=text name=age size=> <br/>
Gender: <br/>
<select size= name=gender>
<option> Select gender </option>
<option value=Male>Male</option>
<option value=Female>Female</option>
</select> <br/>
<input type=submit value=Submit onClick=check();return false;>
</form>
其中Check()函数是用来检测表单内容的
JavaScript函数
<SCRIPT LANGUAGE=JavaScript TYPE=text/javascript>
function check() {
var nameandsurname = documentmyformnameandsurname;
var email = documentmyformemail;
var age = documentmyformage;
var gender = documentmyformgender;
if ( nameandsurnamevalueindexOf( ) == ) {
alert(Enter your Name and Surname);
nameandsurnamefocus();
} else if ((emailvalueindexOf(@) == ) || (emailvalueindexOf() == )) {
alert(Enter your valid email address);
emailfocus();
} else if (! (parseInt(agevalue) > )) {
alert(Enter your Age);
agefocus();
} else if (genderselectedIndex == ) {
alert(Select your gender);
genderfocus();
} else {
documentmyformsubmit();
}
}
</SCRIPT>
把上面的javascript代码放到你的网页的<head> </head>之间就可以了!