查看: 991|回复: 10
|
讯问 checkox 的 coding, 急:(
[复制链接]
|
|
发表于 11-1-2008 10:16 AM
|
显示全部楼层
用 javascript filter ?
在<form> 里加 onsubmit

[ 本帖最后由 vampcheah 于 11-1-2008 04:56 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 11-1-2008 04:06 PM
|
显示全部楼层
例如
<!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>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" c />
</head>
<body>
<script>
function check(){
count = 0;
for(x=0; x<document.form1.checkbox.length; x++){
if(document.form1.checkbox[x].checked==true){
count++
}
}
if(count==0){
alert("You must choose atleast 1");
return false;
}
else if(count>3){
alert("You can only choose upto 3");
return false;
}
else {
alert("ok");
return true;
}
}
</script>
<form name="form1" id="form1" method="post" action="" >
<p>
<input type="checkbox" name="checkbox" value="red" />
Red<br />
<input type="checkbox" name="checkbox" value="green" />
Green<br />
<input type="checkbox" name="checkbox" value="blue" />
Blue<br />
<input type="checkbox" name="checkbox" value="black" />
Black<br />
<input type="checkbox" name="checkbox" value="white" />
White<br />
<input type="checkbox" name="checkbox" value="yellow" />
Yellow<br />
<input type="checkbox" name="checkbox" value="purple" />
Purple
</p>
<p>
<input type="Submit" name="Button" value="Click Me" />
</p>
</form>
</body>
</html>
[ 本帖最后由 cky_2003 于 11-1-2008 04:09 PM 编辑 ] |
|
|
|
|
|
|
|

楼主 |
发表于 12-1-2008 11:51 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 12-1-2008 10:24 PM
|
显示全部楼层
回复 4# 的帖子
例如用最快的方法如下
<script>
function check(){
count = 0;
for(x=0; x<document.form1.checkbox.length; x++){
if(document.form1.checkbox[x].checked==true){
if (document.form1.checkbox[x].value=="other"){
if (document.form1.othervalue.value==""){
alert("Please Key in");
document.form1.othervalue.focus();
return false;
}
}
count++
}
}
if(count==0){
alert("You must choose atleast 1");
return false;
}
else if(count>3){
alert("You can only choose upto 3");
return false;
}
else {
alert("ok");
return true;
}
}
</script>
<form name="form1" id="form1" method="post" >
<input type="checkbox" name="checkbox" value="red" />Red<br />
<input type="checkbox" name="checkbox" value="green" />Green<br />
<input type="checkbox" name="checkbox" value="other" />Other<br>
<input type="text" name="othervalue" value="" disabled/>
</form>
[ 本帖最后由 cky_2003 于 12-1-2008 10:31 PM 编辑 ] |
|
|
|
|
|
|
|

楼主 |
发表于 14-1-2008 07:30 PM
|
显示全部楼层
回复 5# cky_2003 的帖子
再次谢谢你慷慨的帮助,我会试试看 |
|
|
|
|
|
|
|

楼主 |
发表于 15-1-2008 04:05 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 15-1-2008 10:58 PM
|
显示全部楼层
原帖由 ice_jenny 于 15-1-2008 04:05 PM 发表 
接下来的问题是怎样把 checkbox 的资料收入在 database?
因为不知注册者会在几个 checkbox 打钩, 所以不懂在 database 里需要放入几个 text field。
听我的朋友说需在 php coding 的用 array function 置入 ...
发挥下想象空间..
database 那用一个field来存完所有checkbox的结果. 这是比较好的做法.. 开多多个fields这不是方法..
field里要怎样存呢? 有2个..
1. 将field存成 1,0,1,1,1,1 (6个checkbox: 1代表有选,0代表没选)
2. 将field存成 7 (3个checkbox,第一个checkbox+1,第二个checkbox+2,第三个checkbox+4, 如果是7,就代表这3个全选)
这2个方法是较普遍的做法.. 应该知道我讲什么吧?
只是普通数学/逻辑的运用罢了.. |
|
|
|
|
|
|
|
发表于 15-1-2008 11:25 PM
|
显示全部楼层
给我做的话,不用分1/0,直接把所有的input 都 a,b,c,d,e   |
|
|
|
|
|
|
|

楼主 |
发表于 18-1-2008 04:25 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 18-1-2008 06:01 PM
|
显示全部楼层
原帖由 ice_jenny 于 18-1-2008 04:25 PM 发表 
erm...可以给些 sample coding mah....我不知要怎么开头写...
用JAVA Script 来写.. 将东西写成我说的那样就可以了..
现在你都知道要怎样处理资料里, 没理由不懂Script要怎样写..
自己发挥想象空间.. 写程序就是要这样.. |
|
|
|
|
|
|
| |
本周最热论坛帖子
|