js 勾选checkbox的值 写入 下面的输入框

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
.style1 {
font-size: small;
}
</style>
<script type="text/javascript">
function test(form) {
var Q = document.getElementById("city");
Q.value = "";
for (var i=0;i<form.elements.length;i++) {
var e = form.elements[i];
if (e.name == "sc" && e.checked == true) {
Q.value = Q.value + e.value + ","
}
}
}
</script>
<form name="form1" method="post" action="">
<table cellpadding="0" cellspacing="0">
              <tr>
                <td>
     <input name="sc" value="Beijing" type="checkbox" class="style1" onclick="test(this.form)" ><span class="style1">
                  Beijing</span></td>
                <td>
     <input name="sc" type="checkbox" class="style1" id="sc" value="Shanghai"   onclick="test(this.form)"><span class="style1">
                  Shanghai</span></td>
              </tr>
              <tr>
                <td>
     <input name="sc" value="Xian" type="checkbox" class="style1"   onclick="test(this.form)" ><span class="style1">
                  Xi'an</span></td>
                <td>
     <input name="sc" value="Guilin" type="checkbox" class="style1"    onclick="test(this.form)" ><span class="style1">
                  Guilin</span></td>
              </tr>
              <tr>
                <td>
     <input name="sc" value="Lhasa" type="checkbox" class="style1"      onclick="test(this.form)" ><span class="style1">
                  Lhasa, Tibet</span></td>
                <td>
     <input name="sc" value="Yangtze" type="checkbox" class="style1"    onclick="test(this.form)"><span class="style1">
                  Yangtze River</span></td>
              </tr>
            </table>
            <textarea name="city" id="city" rows="2" class="style1"></textarea>
</form>
 
</body>
</html>

posted @ 2013-09-06 17:01  堕落的惜花  阅读(456)  评论(0)    收藏  举报