js处理复选框,提交了之后无反应
意图就是,把被勾选的项目显示在下面的框框里<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=gb2312">
<title>it`s a try for checkbox.</title>
<script type="text/javascript">
function sub()
{
var takeplaceboy=document.getelementsbyname("1");
var takeplacegirl=document.getelementsbyname("2");
if(takeplaceboy=='b'&&takeplacegirl=='g')
{document.显示.value='boy&girl';}
else
if(takeplaceboy!='b'&&takeplacegirl!='g')
{document.显示.value='NULL';}
else
if(takeplaceboy=='b')
{document.显示.value='boy';alert("ok");}
else
{document.显示.value='girl';}
}
</script>
</head>
<body><center>
<form name="myform" method="post" onsubmit=" return sub()">
<input type="checkbox" name="1" value="b"/>boy
<input type="checkbox" name="2" value="g"/>girl
<input type="submit" value="提交"/>
<input type="reset" value="重置"/>
</form>
<input type="text" name="显示" readonly/>
</center></body>
</html>