首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

简单投票系统解决方案

2012-02-05 
简单投票系统htmlheadmeta http-equivContent-Type contenttext/html charsetgb2312 /titl

简单投票系统
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
  <input type="checkbox" name="checkbox" value="checkbox" />
  候选一&nbsp;&nbsp;&nbsp;小计&nbsp;
  <input type="text" name="textfield" />
  </p>
  <p>
  <input type="checkbox" name="checkbox2" value="checkbox" />
  候选二&nbsp;&nbsp;&nbsp;小计&nbsp;
  <input type="text" name="textfield2" />
  </p>
  <p>  
  <input type="checkbox" name="checkbox3" value="checkbox" />
  候选三&nbsp;&nbsp;&nbsp;小计&nbsp;
  <input type="text" name="textfield3" />
  </p>
  <p>  
  <input type="checkbox" name="checkbox4" value="checkbox" />
  候选四&nbsp;&nbsp;&nbsp;小计&nbsp;
  <input type="text" name="textfield4" />
  </p>
  <p>  
  <input type="checkbox" name="checkbox5" value="checkbox" />
  候选五&nbsp;&nbsp;&nbsp;小计&nbsp;
  <input type="text" name="textfield5" />
  </p>
  <p>
  <input type="submit" name="Submit" value="提交" />
  </p>
  <p>有效投票张数:
  <input type="text" name="textfield6" />
  </p>
</form>

</body>
</html>

如上,我希望在每次提交后,就在有被选中的候选人那边加1,同时将有效票那边统计目前为止的有效投票数(用来验证总投票数与个人得票数和是否一致,保证系统准确性。)

[解决办法]
这些应该在服务端做,做客户端做就不安全了
[解决办法]

HTML code
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档 </title> </head> <script>function SetSelect(obj,str){    if (obj.checked)    {        document.getElementById(str).value = parseInt(document.getElementById(str).value) + 1;        document.getElementById("textfield6").value = parseInt(document.getElementById("textfield6").value) + 1;    }    else    {        document.getElementById(str).value = parseInt(document.getElementById(str).value) - 1;        document.getElementById("textfield6").value = parseInt(document.getElementById("textfield6").value) - 1;        }}</script><body> <form id="form1" name="form1" method="post" action="">    <p>      <input type="checkbox" name="checkbox" value="checkbox" onclick="SetSelect(this,'textfield')" />   候选一&nbsp;&nbsp;&nbsp;小计&nbsp;    <input name="textfield" type="text" value="0" />    </p>    <p>      <input type="checkbox" name="checkbox2" value="checkbox"  onclick="SetSelect(this,'textfield2')" />   候选二&nbsp;&nbsp;&nbsp;小计&nbsp;    <input name="textfield2" type="text" value="1" />    </p>    <p>        <input type="checkbox" name="checkbox3" value="checkbox"  onclick="SetSelect(this,'textfield3')" />   候选三&nbsp;&nbsp;&nbsp;小计&nbsp;    <input name="textfield3" type="text" value="2" />    </p>    <p>        <input type="checkbox" name="checkbox4" value="checkbox"  onclick="SetSelect(this,'textfield4')" />   候选四&nbsp;&nbsp;&nbsp;小计&nbsp;    <input name="textfield4" type="text" value="3" />    </p>    <p>        <input type="checkbox" name="checkbox5" value="checkbox"  onclick="SetSelect(this,'textfield5')" />   候选五&nbsp;&nbsp;&nbsp;小计&nbsp;    <input name="textfield5" type="text" value="4" />    </p>    <p>      <input type="submit" name="Submit" value="提交" />    </p>    <p>有效投票张数:      <input name="textfield6" type="text" value="10" />    </p> </form> </body> </html> 


[解决办法]
xmlhttp发送点击动作 处理过程放服务器端 安全 而且比较好处理

热点排行