<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>获取单选框和多选框的值</title>
<script type="text/javascript">
function welcome(){
var name=myform.name.value;
for(var i=0; i<myform.sex.length;i++){
if(myform.sex[i].checked){
var sex=myform.sex[i].value;
}
}
var love="";
for(var i=0; i<myform.myLove.length;i++){
if(myform.myLove[i].checked){
var love =love +" "+ myform.myLove[i].value;
}
}
document.write(name);
if(sex=="man"){
document.write("先生:");
}else{
document.write("欢迎您!<br>");
}
document.write("您的爱好为:",love);
}
</script>
</head>
<body>
<form name="myform" id="myform"method="post" >
姓名:<input type="text" name="name" id="name" value="">
<br>
性别:
男:<input type="radio" value="man" name="sex" checked/>
女:<input type="radio" value="woman" name="sex"/><br>
爱好:<br>
<input type="checkbox" name="myLove" value="打球">打球<br>
<input type="checkbox" name="myLove" value="看书">看书<br>
<input type="checkbox" name="myLove" value="上网">上网<br>
<input type="checkbox" name="myLove" value="旅游">旅游<br>
<br>
<input type="button" value="提交" name="button" onClick="welcome()">
<input type="reset" value="取消" ><br>
</form>
</body>
</html>
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>获取单选框和多选框的值</title>
<script type="text/javascript">
function welcome(){
var name=myform.name.value;
for(var i=0; i<myform.sex.length;i++){
if(myform.sex[i].checked){
var sex=myform.sex[i].value;
}
}
var love="";
for(var i=0; i<myform.myLove.length;i++){
if(myform.myLove[i].checked){
var love =love +" "+ myform.myLove[i].value;
}
}
document.write(name);
if(sex=="man"){
document.write("先生:");
}else{
document.write("欢迎您!<br>");
}
document.write("您的爱好为:",love);
}
</script>
</head>
<body>
<form name="myform" id="myform"method="post" >
姓名:<input type="text" name="name" id="name" value="">
<br>
性别:
男:<input type="radio" value="man" name="sex" checked/>
女:<input type="radio" value="woman" name="sex"/><br>
爱好:<br>
<input type="checkbox" name="myLove" value="打球">打球<br>
<input type="checkbox" name="myLove" value="看书">看书<br>
<input type="checkbox" name="myLove" value="上网">上网<br>
<input type="checkbox" name="myLove" value="旅游">旅游<br>
<br>
<input type="button" value="提交" name="button" onClick="welcome()">
<input type="reset" value="取消" ><br>
</form>
</body>
</html>