<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
	<title>无标题文档</title>
	<script type="text/javascript" language="javascript">
	function checkmsg(){
	var name = document.getElementById("name").value;
	if(name==""){
	alert("请输入您的姓名!");
	document.form1.name.focus();
	return false;
	}
	if(name.length >8){  
	alert("姓名不能超过8个字符!"); 
	name = name.substring(0,8);  
	//document.getElementById("test").value = str.substring(0,8);test是它的type值,而这个地方应该是name值
	//document.getElementById("name").value = str.substring(0,8); 
	return false;
	}
	var age=document.getElementById("age").value;
	//if(document.form1.age.value==""){
	if(age==""){
	alert("请输入您的年龄!");
	document.form1.age.focus();
	return false;
	}
	document.form1.textarea.value="姓名:"+name+"\n年龄:"+age+"\n"+choices();
	}
	function choices(){
	 f=document.forms[0];
	 str1="",str2="",str3="";
	 for(i=0;i<f.sex.length;i++){
	  if(f.sex[i].checked){
	   str1="性别:"+f.sex[i].value+"";
	  }
	 }
	 for(i=0;i<f.favorite.length;i++){
	  if(f.favorite[i].checked){
	   str2="爱好:"+f.favorite[i].value+"";
	  }
	 }
	 sel = document.forms[0].select
	    str3 = sel.options[sel.selectedIndex].text
	 return str=str1+"\n"+str2+"\n所在城市:"+str3;
	}
	</script>
	</head>
	<body  bgcolor="#99FFCC">
	<form id="form1" name="form1" method="post" action="">
	  <table width="453" align="center" bgcolor="#FFFF99">
	    <tr>
	      <td width="92">姓名:</td>
	      <td width="349"><label>
	        <input type="text" name="name" id="name"/>
	      </label></td>
	    </tr>
	    <tr>
	      <td>性别:</td>
	      <td><label>
	        <input type="radio" name="sex" checked="checked" value="男"/>男
	      </label>
	        <label>
	        <input type="radio" name="sex" value="女"/>女
	      </label></td>
	    </tr>
	    <tr>
	      <td>年龄:</td>
	      <td><label>
	        <input type="text" name="age" id="age"/>
	      </label></td>
	    </tr>
	    <tr>
	      <td>爱好;</td>
	      <td><label>
	        <input type="checkbox" name="favorite" value="上网" checked="checked"/>上网
	      </label>
	        <label>
	        <input type="checkbox" name="favorite" value="旅游" />旅游
	      </label>
	        <label>
	        <input type="checkbox" name="favorite" value="打电脑" />打电脑
	      </label>
	        <label>
	        <input type="checkbox" name="favorite" value="看书" />看书
	      </label></td>
	    </tr>
	    <tr>
	      <td>所在城市</td>
	      <td><label>
	        <select name="select">
	          <option>南阳</option>
	          <option>信阳</option>
	          <option>商丘</option>
	          <option>郑州</option>
	        </select>
	      </label></td>
	    </tr>
	    <tr>
	      <td> </td>
	      <td><input type="button" name="submit" value="提交" onclick="checkmsg()"/>
	   <input type="reset" value="重置" /></td>
	    </tr>
	  <tr>
	      <td>显示信息框:</td>
	      <td><label>
	        <textarea name="textarea" cols="20" rows="10" id="a"></textarea>
	      </label></td>
	    </tr>
	  </table>
	</form>
	</body>
	</html>